Exercise: Lists

Questions for: Lists

How can you concatenate two lists in Python?
A:
list1.concatenate(list2)
B:
list1 + list2
C:
list1.extend(list2)
D:
list1.concat(list2)
Answer: B
The + operator is used to concatenate two lists in Python.
What is the purpose of the copy method in Python lists?
A:
To create a deep copy of the list.
B:
To create a shallow copy of the list.
C:
To copy elements from one list to another.
D:
To concatenate two lists.
Answer: B
The copy method in Python lists is used to create a shallow copy of the list.
What is the purpose of the clear method in Python lists?
A:
To remove the last element from the list.
B:
To remove all occurrences of a specific element.
C:
To remove all elements from the list.
D:
To remove elements from the list based on a condition.
Answer: C
The clear method in Python lists is used to remove all elements from the list, leaving it empty.
How can you check if a specific element is present in a list in Python?
A:
check(element) in my_list
B:
element in my_list
C:
contains(element, my_list)
D:
my_list.contains(element)
Answer: B
The expression element in my_list is used to check if a specific element is present in a list.
What is the purpose of the index method in Python lists?
A:
To find the index of the last occurrence of a specific element.
B:
To find the index of the first occurrence of a specific element.
C:
To find the total number of elements in the list.
D:
To find the index of the maximum element in the list.
Answer: B
The index method in Python lists is used to find the index of the first occurrence of a specific element.
Ad Slot (Above Pagination)
Quiz