Python Programming - Lists

Exercise : Lists - General Questions
  • Lists - General Questions
1.
How do you remove an element from a list in Python?
remove(element)
pop(index)
delete(element)
discard(element)
Answer: Option
Explanation:
The pop(index) method is used to remove and return the element at the specified index in a list.

2.
Which method is used to add elements from one list to another in Python?
concat()
merge()
extend()
append()
Answer: Option
Explanation:
The extend() method is used to add elements from one list to the end of another list.

3.
What is the correct way to sort a list in descending order in Python?
list.sort()
sorted(list, reverse=True)
list.sort(reverse=True)
sorted(list)
Answer: Option
Explanation:
The list.sort(reverse=True) method is used to sort a list in descending order in-place.

4.
What does the index method of a list return in Python?
The first occurrence of the specified element.
The last occurrence of the specified element.
The index of the specified element.
The count of occurrences of the specified element.
Answer: Option
Explanation:
The index method returns the index of the first occurrence of the specified element in a list.

5.
Which function is used to create a shallow copy of a list in Python?
copy()
clone()
duplicate()
replicate()
Answer: Option
Explanation:
The copy() function is used to create a shallow copy of a list in Python.