List Exercises
3 min read ·
These exercises are designed to strengthen your understanding of Python lists step by step.
They cover accessing, modifying, looping, methods, logic, and tricky behaviors.
Exercise 1: Create and Print a List
Create a list of five integers and print it.
Exercise 2: Access List Items
Print:
- First item
- Last item
- Third item
Exercise 3: Change List Items
Change the second element of the list to
99.Exercise 4: Add Items to a List
Add
60 at the end and 5 at the beginning.Exercise 5: Remove Items from a List
Remove:
- Value
20 - Last item
Exercise 6: Loop Through a List
Print each element using a
for loop.Exercise 7: Loop Using Index
Print index and value.
Exercise 8: Count Occurrences
Count how many times
2 appears.Exercise 9: Sort a List
Sort the list in ascending and descending order.
Exercise 10: Copy a List Correctly
Create a copy and modify only the copied list.
Exercise 11: Join Two Lists
Join two lists into one.
Exercise 12: List Slicing
Print:
- First three items
- Last two items
Exercise 13: Remove Even Numbers (Logic)
Remove all even numbers from the list.
Exercise 14: Find Largest and Smallest Element
Exercise 15: Reverse a List
Exercise 16: Nested List Access
Print the value
5.Exercise 17: Flatten a Nested List
Exercise 18: Check Item Exists
Check if
"apple" exists.Exercise 19: List Length Without len()
Exercise 20: Tricky Reference Question
Predict the output.
Key Learning Outcomes
- List indexing and slicing
- Adding and removing items
- Looping techniques
- List methods usage
- Copy vs reference
- Logical list manipulation
These exercises cover real interview-level understanding of Python lists.