Python Lists

Ordered, changeable collections.

✍️ 3 exercises + code challenge in this lesson

A list stores multiple items in one variable: fruits = ["mango", "apple", "banana"]

  • Lists are ordered, changeable and allow duplicates.
  • Access by index: fruits[0], fruits[-1]; slice with fruits[1:3].
  • Change an item: fruits[1] = "kiwi"
  • Add: append(), insert(), extend()
  • Remove: remove(), pop(), del, clear()
  • Sort: sort(), sort(reverse=True), reverse()
  • Copy: copy() or list(x)

Key Takeaways: Python Lists

Mastering Python Lists helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Python Lists Code Example

Python
fruits = ["mango", "apple", "banana"]
fruits.append("orange")
fruits.insert(1, "kiwi")
print(fruits)

fruits.remove("apple")
last = fruits.pop()
print("Popped:", last, "| List:", fruits)

fruits.sort()
print("Sorted:", fruits)
print("Count:", len(fruits), "| First two:", fruits[:2])

for i, fruit in enumerate(fruits, start=1):
    print(i, fruit)
Free sign-in required · Google login available

Python Lists Practice Exercises

Check what you learned in “Python Lists”.

/ 3 solved
Fill in the blank

Add an item to the end of the list.

fruits.("kiwi")
✓ Correct! Not quite. Try again.
Multiple choice

Which method removes and returns the last item?

✓ Correct! Not quite. Try again.
Code challenge

Sort the list and print it.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services