0% found this document useful (0 votes)
8 views

Which of the following methods is used to add an element to the end of a list in Python

Uploaded by

TVIS Juniors
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Which of the following methods is used to add an element to the end of a list in Python

Uploaded by

TVIS Juniors
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Which of the following methods is used to add an element to the end of a list in Python?

a) append()

b) add()

c) insert()

d) extend()

Q2. What is the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
print(my_list[2:4])
Copy Code

a) [3, 4]

b) [2, 3, 4]

c) [1, 2, 3]

d) [4, 5]

Q3. Which of the following methods is used to remove the first occurrence of a specified
element from a list in Python?

a) remove()

b) pop()

c) delete()

d) discard()

Q4. What will be the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.pop(2)
print(my_list)
Copy Code

a) [1, 2, 4, 5]

b) [1, 2, 3, 5]

c) [1, 2, 4]

d) [1, 2, 3, 4]

Q5. Which of the following methods is used to reverse the elements of a list in Python?

a) reverse()

b) sort()

c) swap()

d) invert()

Q6. What is the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
my_list.extend([6, 7, 8])
print(my_list)
Copy Code

a) [1, 2, 3, 4, 5, 6, 7, 8]

b) [1, 2, 3, 4, 5, [6, 7, 8]]

c) [1, 2, 3, 4, 5, (6, 7, 8)]

d) [1, 2, 3, 4, 5, {6, 7, 8}]


Q7. Which of the following methods is used to sort the elements of a list in Python?

a) sort()

b) order()

c) arrange()

d) organize()

Q8. What will be the output of the following Python code snippet?

my_list = [3, 2, 1, 4, 5]
my_list.sort()
print(my_list)
Copy Code

a) [1, 2, 3, 4, 5]

b) [5, 4, 3, 2, 1]

c) [3, 2, 1, 4, 5]

d) [1, 3, 2, 4, 5]

Q9. Which of the following methods is used to insert an element at a specified position in a
list in Python?

a) insert()

b) add()

c) append()

d) put()
Q10. What is the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
my_list.insert(2, 10)
print(my_list)
Copy Code

a) [1, 2, 10, 3, 4, 5]

b) [1, 2, 3, 10, 4, 5]

c) [1, 2, 3, 4, 10, 5]

d) [1, 2, 3, 4, 5, 10]

Q11. Which of the following methods is used to remove the element at a specified

position in a list in Python?

a) remove()

b) pop()

c) delete()

d) discard()

Q12. What will be the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
Copy Code

a) [1, 2, 4, 5]

b) [1, 2, 3, 4]

c) [1, 2, 4]

d) [1, 2, 5]
Q13. Which of the following methods is used to count the number of occurrences of a
specified element in a list in Python?

a) count()

b) occurrences()

c) find()

d) search()

Q14. What will be the output of the following Python code snippet?

my_list = [1, 2, 2, 3, 4, 2, 5]
print(my_list.count(2)) Copy Code

a) 1

b) 2

c) 3

d) 4

Q15. Which of the following methods is used to create a shallow copy of a list in Python?

a) copy()

b) clone()

c) duplicate()

d) replicate()
Q16. What will be the output of the following Python code snippet?

my_list = [1, 2, 3]
new_list = my_list.copy()
my_list.append(4)
print(new_list)
Copy Code

a) [1, 2, 3]

b) [1, 2, 3, 4]

c) [1, 2, 3, 4]

d) [1, 2, 3, 4]

Q17. Which of the following methods is used to clear all elements from a list in Python?

a) clear()

b) empty()

c) remove_all()

d) erase()

Q18. What will be the output of the following Python code snippet?

my_list = [1, 2, 3]
my_list.clear()
print(my_list)
Copy Code

a) []

b) [None]

c) [1, 2, 3]

d) [0, 0, 0]
Q19. Which of the following methods is used to find the index of the first occurrence of a
specified element in a list in Python?

a) index()

b) find()

c) search()

d) locate()

Q20. What will be the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
print(my_list.index(3))
Copy Code

a) 2

b) 3

c) 4

d) 5

Q21. Which of the following methods is used to concatenate two lists in Python?

a) extend()

b) concat()

c) join()

d) merge()
Q22. What will be the output of the following Python code snippet?

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
Copy Code

a) [1, 2, 3, 4, 5, 6]

b) [1, 2, 3, [4, 5, 6]]

c) [1, 2, 3, (4, 5, 6)]

d) [1, 2, 3, {4, 5, 6}]

Q23. Which of the following methods is used to reverse the order of elements in a list in
Python?

a) reverse()

b) invert()

c) flip()

d) backward()

Q24. What will be the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
my_list.reverse()
print(my_list)
Copy Code

a) [1, 2, 3, 4, 5]

b) [5, 4, 3, 2, 1]

c) [5, 4, 3, 2, 1, 0]
d) [1, 2, 3, 4]

Q25. Which of the following methods is used to sort the elements of a list in descending
order in Python?

a) sort()

b) sort_desc()

c) sort(reverse=True)

d) sort(descending=True)

Q26. What will be the output of the following Python code snippet?

my_list = [5, 2, 8, 1, 3]
my_list.sort(reverse=True)
print(my_list)
Copy Code

a) [5, 2, 8, 1, 3]

b) [1, 2, 3, 5, 8]

c) [8, 5, 3, 2, 1]

d) [1, 3, 5, 8]

Q27. Which of the following methods is used to remove the element with the highest value

from a list in Python?

a) pop()

b) remove_max()

c) remove()

d) clear()
Q28. What will be the output of the following Python code snippet?

my_list = [1, 2, 3, 4, 5]
my_list.pop()
print(my_list)
Copy Code

a) [1, 2, 3, 4]

b) [1, 2, 3]

c) [2, 3, 4, 5]

d) [1, 2, 3, 4, 5]

Q29. Which of the following methods is used to remove all occurrences of a specified
element from a list in Python?

a) remove_all()

b) delete()

c) remove()

d) clear()

Q30. What will be the output of the following Python code snippet?

nums = [1, 2, 3, 4, 5]
result = [x for x in nums if x % 2 == 0]
print(result)
Copy Code

a) [2, 4]

b) [1, 3, 5]

c) [1, 2, 3, 4, 5]

d) [1, 4]
Q31. What does the following Python code snippet do?

words = ["apple", "banana", "orange"]


lengths = [len(word) for word in words]
print(lengths)
Copy Code

a) [5, 6, 6]

b) [“apple”, “banana”, “orange”]

c) [0, 0, 0]

d) [1, 1, 1]

Q32. What is the output of the following Python code snippet?

numbers = [1, 2, 3, 4, 5]
result = [num * 2 for num in numbers]
print(result)
Copy Code

a) [1, 4, 9, 16, 25]

b) [2, 4, 6, 8, 10]

c) [2, 4, 6, 8, 10]

d) [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

Q33. What will be the output of the following Python code snippet?

words = ["apple", "banana", "orange"]


result = [word.upper() for word in words]
print(result)Copy Code

a) [“APPLE”, “BANANA”, “ORANGE”]

b) [“apple”, “banana”, “orange”]

c) [“Apple”, “Banana”, “Orange”]

d) [“A”, “B”, “O”]

You might also like