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.