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

List Functions

Uploaded by

sridhar k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

List Functions

Uploaded by

sridhar k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Which of the following methods adds an item to a list?

 A) append()
 B) extend()
 C) add()
 D) insert()
2. What does the extend() method do in Python lists?
 A) Extends the length of a list by 1
 B) Adds multiple items from another list
 C) Multiplies the length of a list
 D) Makes the list immutable
3. What is the output of the following code?
pythonCopy code
list1 = [ 1 , 2 , 3 ] list1.extend([ 4 , 5 ])
 A) [1,2,3,4,5]
 B) [1,2,3,[4,5]]
 C) [4,5,1,2,3]
 D) [1,2,3]
4. Which of the following methods removes the first occurrence of a value in a
list?
 A) pop()
 B) del()
 C) discard()
 D) remove()
5. How do you find the index of the first occurrence of a value in a list?
 A) find()
 B) index()
 C) locate()
 D) position()
6. What is the output of the following code?
pythonCopy code
list2 = [ 1 , 2 , 3 , 4 , 5 ] list2.pop( 2 )
A) 3

 B) 2
 C) 4
 D) 5
7. How can you reverse the elements of a list in-place?
 A) reversed(list)
 B) list.reverse()
 C) list.sort(reverse=True)
 D) list[::-1]
8. How can you get a sorted list without modifying the original list?
 A) sort(list)
 B) list.sort()
 C) sorted(list)
 D) list.sorted()
9. Which of the following is used to insert an item at a specific position?
 A) insert()
 B) append()
 C) add()
 D) push()
10. What is the output of len([1, 2, [3, 4], 5])?
 A) 5
 B) 4
 C) 6
 D) 7
11. How would you remove all items from a list named 'mylist'?
 A) del mylist
 B) mylist.remove()
 C) mylist = []
 D) mylist.clear()
12. What does the method count() do?
 A) Returns the number of items in a list
 B) Returns the total of all items in the list
 C) Returns the number of occurrences of a value
 D) Counts and removes a value from a list
13. What is the output of list("Hello") ?
 A) ['Hello']
 B) 'Hello'
 C) ['H', 'e', 'l', 'l', 'o']
 D) ['He', 'llo']
14. What is the result of list(range(3))?
 A) [0, 1, 2]
 B) [0, 1, 2, 3]
 C) [1, 2, 3]
 D) None
15. How do you copy a list in Python?
 A) copy.list()
 B) list.copy()
 C) list.duplicate()
 D) copy()
16. What does list1 + list2 do for two lists list1 and list2 ?
 A) Multiply them
 B) Compare them
 C) Concatenate them
 D) Divide them
17. How can you add a list into another list?
 A) use append()
 B) use extend()
 C) use insert()
 D) use add()
18. What will ['a', 'b', 'c'] * 3 produce?
 A) ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
 B) ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
 C) ['a', 'b', 'c', 3]
 D) Error
19. If list1 = [1,2,3] , what is the output of list1.append([4,5]) ?
 A) [1,2,3,4,5]
 B) [1,2,3,[4,5]]
 C) [4,5,1,2,3]
 D) [1,2,3]
20. What is the output of min([5,2,7,1])?
 A) 1
 B) 5
 C) 7
 D) 2
21. How do you check if a list is empty?
 A) if list == []
 B) if len(list) == 0
 C) if not list
 D) All of the above
22. How can you join two lists together?
 A) list1.join(list2)
 B) join(list1, list2)
 C) list1 + list2
 D) list1.concat(list2)
23. Which method returns the smallest item from the list?
 A) least()
 B) smallest()
 C) min()
 D) tiny()
24. How can you remove the item at index 2 from a list?
 A) list.remove(2)
 B) list.pop(2)
 C) del list[2]
 D) Both B and C
25. Which of the following is NOT a valid way to create a list in Python?
 A) list1 = list()
 B) list2 = []
 C) list3 = list:[]
 D) list4 = [1,2,3]
26. Which method would you use to get a list of all the methods available for a
list object?
 A) methods()
 B) functions()
 C) dir()
 D) help()
27. How can you convert a tuple into a list?
 A) list(tuple)
 B) tuple.toList()
 C) convert(tuple)
 D) toList(tuple)
28. What is the output of max([5,2,7,1])?
 A) 1
 B) 5
 C) 7
 D) 2
29. Which of the following would sort the list in descending order?
 A) list.sort(ascending=False)
 B) list.sort(descend=True)
 C) list.sort(reverse=True)
 D) list.reverse_sort()
30. Which function returns the number of items in a list?
 A) len()
 B) count()
 C) size()
 D) number()

Answers:

1. A
2. B
3. A
4. D
5. B
6. A
7. B
8. C
9. A
10. B
11. D
12. C
13. C
14. A
15. B
16. C
17. A
18. A
19. B
20. A
21. D
22. C
23. C
24. D
25. C
26. C
27. A
28. C
29. C
30. A

You might also like