List in python: 20 MCQs with answers
All 20 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 12 questions
Q1. Which of the following correctly creates a list in Python?
BeginnerShow answer & explanation
list = [1, 2, 3]
Square brackets `[]` are used to create a list in Python. Curly braces create a set, parentheses create a tuple, and angle brackets are not valid.
Q2. What is the index of the first element in a Python list?
BeginnerShow answer & explanation
0
Python uses zero-based indexing, so the first element is at index 0.
Q3. Given `my_list = [10, 20, 30, 40]`, what does `my_list[-1]` return?
BeginnerShow answer & explanation
40
Negative indexing starts from the end; `-1` refers to the last element, which is 40.
Q4. What is the result of `len([1, 2, 3, 4])`?
BeginnerShow answer & explanation
4
The `len()` function returns the number of elements in the list, which is 4.
Q5. Which method adds an element to the end of a list?
BeginnerShow answer & explanation
append()
`append()` adds a single element to the end. `insert()` adds at a specific index, `extend()` adds multiple elements, and `add()` is not a list method.
Q6. What does `[1, 2, 3] + [4, 5]` produce?
BeginnerShow answer & explanation
[1, 2, 3, 4, 5]
The `+` operator concatenates two lists, producing a new list with all elements from both.
Q7. What is the output of `[1, 2, 3] * 2`?
BeginnerShow answer & explanation
[1, 2, 3, 1, 2, 3]
The `*` operator repeats the list the specified number of times, so `[1, 2, 3] * 2` yields `[1, 2, 3, 1, 2, 3]`.
Q8. Lists in Python are immutable.
BeginnerShow answer & explanation
False
Lists are mutable, meaning their elements can be changed after creation.
Q9. The index `-1` always refers to the last element of a list.
BeginnerShow answer & explanation
True
Negative indices count from the end, with `-1` being the last element.
Q10. You can use the `+` operator to concatenate two lists.
BeginnerShow answer & explanation
True
The `+` operator concatenates lists, producing a new list.
Q11. The method used to add an element to the end of a list is ___.
BeginnerShow answer & explanation
—
`append()` adds a single element to the end of the list.
Q12. To find the number of elements in a list, use the ___ function.
BeginnerShow answer & explanation
—
`len()` returns the length (number of items) of a list.
Building up · 8 questions
Q13. Which of the following checks if 5 is in a list `nums`?
IntermediateShow answer & explanation
5 in nums
The `in` keyword is used to check membership in a list. `nums.contains()` and `nums.has()` are not valid Python methods.
Q14. What does `[10, 20, 30, 40, 50][1:4]` return?
IntermediateShow answer & explanation
[20, 30, 40]
Slicing `[start:end]` includes elements from index `start` up to but not including `end`. So `[1:4]` gives indices 1, 2, 3: `[20, 30, 40]`.
Q15. What is the result of `[1, 2, 3].pop()`?
IntermediateShow answer & explanation
3
`pop()` removes and returns the last element by default. The last element is 3.
Q16. Which of the following removes the first occurrence of a value from a list?
IntermediateShow answer & explanation
remove()
`remove()` removes the first occurrence of a specified value. `pop()` removes by index, `delete()` is not a list method, and `discard()` is for sets.
Q17. What is the output of `[x*2 for x in [1, 2, 3]]`?
IntermediateShow answer & explanation
[2, 4, 6]
This is a list comprehension that multiplies each element by 2, resulting in `[2, 4, 6]`.
Q18. The `insert()` method adds an element to the end of a list.
IntermediateShow answer & explanation
False
`insert()` adds an element at a specified index, not necessarily the end. `append()` adds to the end.
Q19. Slicing a list always returns a new list.
IntermediateShow answer & explanation
True
Slicing creates a new list containing the selected elements.
Q20. A list can contain elements of different data types; this property is called ___.
IntermediateShow answer & explanation
—
Python lists are heterogeneous, meaning they can store mixed data types.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages