### 🐍 Top 10 Python List `insert()` Quiz
Test your Python knowledge with these 10 output-based multiple-choice questions.
### Q1. What is the output?
A. \[1, 2, 10, 3\]
B. \[1, 10, 2, 3\]
C. \[10, 1, 2, 3\]
D. \[1, 2, 3, 10\]
### Q2. What is the output?
A. \[5, 6, 7, 100\]
B. \[100, 5, 6, 7\]
C. \[5, 100, 6, 7\]
D. \[100, 7, 6, 5\]
### Q3. What is the output?
A. \[4, 1, 2, 3\]
B. \[1, 2, 4, 3\]
C. \[1, 2, 3, 4\]
D. Error
### Q4. What is the output?
A. \[99, 10, 20, 30\]
B. \[10, 20, 99, 30\]
C. \[10, 20, 30, 99\]
D. \[10, 99, 20, 30\]
### Q5. What is the output?
A. Error
B. \[5, 1, 2\]
C. \[1, 2, 5\]
D. \[1, 5, 2\]
### Q6. What is the output?
A. \[2, 8, 10, 4, 6\]
B. \[2, 8, 4, 10, 6\]
C. \[2, 4, 10, 8, 6\]
D. \[8, 2, 10, 4, 6\]
### Q7. What is the output?
A. \[1, 99, 2, 3\]
B. 99
C. None
D. True
### Q8. What is the output?
A. \[1, 2, 3, 9\]
B. \[9, 1, 2, 3\]
C. \[1, 9, 2, 3\]
D. Error
### Q9. What is the output?
A. \[1, 4, 5, 2, 3\]
B. \[1, \[4, 5\], 2, 3\]
C. \[4, 5, 1, 2, 3\]
D. Error
### Q10. What is the output?
A. \[10, 20, 15, 25, 30, 40\]
B. \[10, 20, 25, 15, 30, 40\]
C. \[10, 15, 20, 25, 30, 40\]
D. \[10, 20, 30, 15, 25, 40\]
### 📌 Key Takeaways
* `insert(index, value)` adds an element at a specific position.
* Existing elements shift to the right.
* `insert()` modifies the original list.
* `insert()` returns `None`.
* Large positive indexes append to the end.
* Negative indexes count from the end, with boundary clamping.
Share your score! How many did you get correct? 🐍
1 comment:
### Q1. What is the output?
A. \[1, 2, 10, 3\]
B. \[1, 10, 2, 3\]
C. \[10, 1, 2, 3\]
D. \[1, 2, 3, 10\]
✅ Correct!
`insert(1, 10)` places 10 at index 1.
### Q2. What is the output?
A. \[5, 6, 7, 100\]
B. \[100, 5, 6, 7\]
C. \[5, 100, 6, 7\]
D. \[100, 7, 6, 5\]
✅ Correct!
Index 0 inserts the value at the beginning.
### Q3. What is the output?
A. \[4, 1, 2, 3\]
B. \[1, 2, 4, 3\]
C. \[1, 2, 3, 4\]
D. Error
✅ Correct!
Index 3 is the position after the last element.
### Q4. What is the output?
A. \[99, 10, 20, 30\]
B. \[10, 20, 99, 30\]
C. \[10, 20, 30, 99\]
D. \[10, 99, 20, 30\]
✅ Correct!
Index -1 refers to the position before the last element when inserting.
### Q5. What is the output?
A. Error
B. \[5, 1, 2\]
C. \[1, 2, 5\]
D. \[1, 5, 2\]
✅ Correct!
An index beyond the list's end appends the value.
### Q6. What is the output?
A. \[2, 8, 10, 4, 6\]
B. \[2, 8, 4, 10, 6\]
C. \[2, 4, 10, 8, 6\]
D. \[8, 2, 10, 4, 6\]
✅ Correct!
After inserting 8, index 2 contains 4, so 10 is inserted before 4.
### Q7. What is the output?
A. \[1, 99, 2, 3\]
B. 99
C. None
D. True
✅ Correct!
`insert()` modifies the list in place and returns `None`.
### Q8. What is the output?
A. \[1, 2, 3, 9\]
B. \[9, 1, 2, 3\]
C. \[1, 9, 2, 3\]
D. Error
✅ Correct!
An excessively negative index is clamped to the beginning.
### Q9. What is the output?
A. \[1, 4, 5, 2, 3\]
B. \[1, \[4, 5\], 2, 3\]
C. \[4, 5, 1, 2, 3\]
D. Error
✅ Correct!
`insert()` adds the entire list as one element (a nested list).
### Q10. What is the output?
A. \[10, 20, 15, 25, 30, 40\]
B. \[10, 20, 25, 15, 30, 40\]
C. \[10, 15, 20, 25, 30, 40\]
D. \[10, 20, 30, 15, 25, 40\]
✅ Correct!
After inserting 25 at index 2, inserting 15 at index 2 places it before 25.
Post a Comment