Python Lists Quiz
Welcome to the Python Lists Quiz!
Lists are one of the most important data structures in Python, allowing you to store and manipulate collections of items efficiently. This quiz will test your understanding of lists, including indexing, slicing, methods, and advanced operations.
Each question has four options, but only one correct answer. Good luck!
Table of Contents:
- Python quizzes for beginners series
Lists Quiz
Quiz Questions
1. What is a list in Python?
a) A collection of key-value pairs
b) An immutable sequence of characters
c) An ordered, mutable collection of elements
d) A set of unique elements
Answer
c) An ordered, mutable collection of elements
2. How do you create an empty list?
a) list = ()
b) list = {}
c) list = []
d) list = None
Answer
c) list = []
3. What will len([1, 2, 3, 4])
return?
a) 3
b) 4
c) 5
d) Error
Answer
b) 4
4. What will list(range(4))
return?
a) [1, 2, 3, 4]
b) [0, 1, 2, 3, 4]
c) [0, 1, 2, 3]
d) (0, 1, 2, 3)
Answer
c) [0, 1, 2, 3]
5. What is the index of the last element in my_list = [10, 20, 30, 40]
?
a) 3
b) 4
c) -1
d) 40
Answer
a) 3
6. How do you access the second element of my_list = ['a', 'b', 'c', 'd']
?
a) my_list[2]
b) my_list[1]
c) my_list[-2]
d) my_list(2)
Answer
b) my_list[1]
7. What does my_list[-1]
return?
a) The first element
b) The last element
c) An error
d) None
Answer
b) The last element
8. What will my_list = [1, 2, 3]; my_list.append(4)
result in?
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 3, [4]]
d) (1, 2, 3, 4)
Answer
b) [1, 2, 3, 4]
9. What method is used to remove an element by value?
a) delete()
b) remove()
c) pop()
d) discard()
Answer
b) remove()
10. What will my_list.pop()
do?
a) Remove and return the last element
b) Remove and return the first element
c) Delete the list
d) Cause an error
Answer
a) Remove and return the last element
11. What does my_list.extend([5, 6])
do?
a) Adds [5,6]
as a single element
b) Replaces the list with [5,6]
c) Adds 5 and 6 separately
d) Causes an error
Answer
c) Adds 5 and 6 separately
12. What is the result of my_list = [1, 2, 3] + [4, 5]
?
a) [1, 2, 3, 4, 5]
b) [[1, 2, 3], [4, 5]]
c) [1, 2, 3, [4, 5]]
d) Error
Answer
a) [1, 2, 3, 4, 5]
13. What does my_list.insert(2, 99)
do?
a) Inserts 99 at index 2
b) Adds 99 at the end
c) Removes index 2
d) Causes an error
Answer
a) Inserts 99 at index 2
14. What is the result of sorted([3, 1, 4, 2])
?
a) [3, 1, 4, 2]
b) [4, 3, 2, 1]
c) [1, 2, 3, 4]
d) {1, 2, 3, 4}
Answer
c) [1, 2, 3, 4]
15. What does my_list.reverse()
do?
a) Returns a reversed copy
b) Modifies my_list
in place
c) Sorts the list
d) Causes an error
Answer
b) Modifies my_list
in place
16. Which method is used to count occurrences of an element?
a) index()
b) count()
c) find()
d) search()
Answer
b) count()
17. What happens if you do del my_list[1]
?
a) Deletes the first element
b) Deletes the second element
c) Deletes the last element
d) Causes an error
Answer
b) Deletes the second element
18. What is the output of print([1, 2] * 2)
?
a) [1, 2, 1, 2]
b) [2, 4]
c) [1, 2, [1, 2]]
d) [1, 1, 2, 2]
Answer
a) [1, 2, 1, 2]
19. What is the output of [i**2 for i in range(3)]
?
a) [0, 1, 4]
b) [1, 4, 9]
c) [0, 1, 2]
d) [1, 2, 3]
Answer
a) [0, 1, 4]
20. How do you check if an element exists in a list?
a) exists(x, my_list)
b) x in my_list
c) my_list.has(x)
d) find(x, my_list)
Answer
b) x in my_list
How did you do? 🎯
- 18-20 correct → 🏆 Excellent! You’re a Python functions pro!
- 14-17 correct → 👍 Great job! Keep practicing.
- 10-13 correct → 🙂 Good, but there’s room for improvement.
- Below 10 → 🤔 No worries! Review the concepts and try again.