Python List Exercises

Exercise 1: Create a List and Print It

Question

Create a list of fruits and print it.

Solution

fruits = ["apple", "banana", "orange"]
print(fruits)

Exercise 2: Access List Items

Question

Print the first and last item of a list.

Solution

numbers = [10, 20, 30, 40]

print(numbers[0])
print(numbers[-1])

Exercise 3: Change List Item

Question

Change "banana" to "mango" in the list.

Solution

fruits = ["apple", "banana", "orange"]
fruits[1] = "mango"
print(fruits)

Exercise 4: Add Item to List

Question

Add "grape" to the list.

Solution

fruits.append("grape")
print(fruits)

Exercise 5: Remove Item from List

Question

Remove "apple" from the list.

Solution

fruits.remove("apple")
print(fruits)

Exercise 6: Loop Through List

Question

Print all items in the list using a loop.

Solution

colors = ["red", "blue", "green"]

for color in colors:
print(color)

Exercise 7: Find Length of List

Question

Find how many items are in a list.

Solution

print(len(colors))

Exercise 8: Check Item Exists

Question

Check if "blue" is in the list.

Solution

print("blue" in colors)

Exercise 9: Sort a List

Question

Sort a list of numbers.

Solution

nums = [4, 1, 3, 2]
nums.sort()
print(nums)

Exercise 10: Copy a List

Question

Create a copy of a list and change the copy.

Solution

list1 = [1, 2, 3]
list2 = list1.copy()

list2.append(4)

print(list1)
print(list2)

Exercise 11: Join Two Lists

Question

Join two lists into one.

Solution

a = [10, 20]
b = [30, 40]

c = a + b
print(c)

Exercise 12: List Comprehension

Question

Create a new list with double values.

Solution

nums = [1, 2, 3]
new_nums = [n * 2 for n in nums]
print(new_nums)

Exercise 13: Remove Even Numbers

Question

Remove even numbers from the list.

Solution

nums = [1, 2, 3, 4, 5]

for n in nums[:]:
if n % 2 == 0:
nums.remove(n)

print(nums)

Exercise 14: Count an Item

Question

Count how many times 2 appears.

Solution

nums = [1, 2, 2, 3, 2]
print(nums.count(2))

Exercise 15: Reverse a List

Question

Reverse the list.

Solution

nums.reverse()
print(nums)

✅ Summary

✔ Lists store many values
✔ Lists can be changed
✔ Use methods to work easily
✔ Practice makes you better

📘 Perfect for Beginner eBook

This exercise chapter is ideal for:

  • Python beginner books

  • School & college students

  • Self-learners

If you want next, I can write:

  • Tuple Exercises

  • Set Exercises

  • Dictionary Exercises

  • Loop Exercises

  • MCQs with answers

Just tell me 😊

You may also like...