← Lesson
BitWithBite
Python · Quick Reference

Lesson 8 — Lists & Tuples Cheat Sheet

Python
In one line: Both lists and tuples store ordered sequences of items and support indexing, slicing, and for loops. The key difference is mutability: lists can be changed after creation; tuple...

Key Ideas

1Lists vs Tuples at a Glance. Both lists and tuples store ordered sequences of items and support indexing, slicing, and for loops. The key difference is mutability: lists can be changed after creat...
2Creating & Accessing Lists. A list is created with square brackets [ ]. Items can be of any type — even mixed types or other lists. Access items with an index (0-based), and use negative indexes ...
3Essential List Methods. Lists come with powerful built-in methods. These are called with dot notation: list.method(). Unlike string methods, most list methods modify the list in-place and ret...
4List Comprehensions. A list comprehension is Python's most elegant feature for creating lists. It collapses a loop-and-append pattern into a single, readable line. Once you learn it, you'l...
5Tuples — Immutable Sequences. Tuples are created with parentheses ( ) or just commas. They support indexing, slicing, and for loops exactly like lists — but you cannot add, remove, or change their ...

Code Examples

# Creating lists fruits = ["apple", "banana", "mango", "grape"] marks = [85, 92, 78, 95, 88] mixed = ["Ali", 21, True, 3.14] # any types allowed empty = [] # empty list nested = [[1,2], [3,4], [5,6]] # list of lists # In...
students = ["Ali", "Sara", "Zara"] students.append("Omar") # add to end students.insert(1, "Bilal") # insert at index 1 print(students) # ['Ali', 'Bilal', 'Sara', 'Zara', 'Omar'] students.remove("Zara") # remove by value last = stu...
# Old way: loop + append squares = [] for i in range(1, 6): squares.append(i ** 2) # Comprehension — same result, one line squares = [i ** 2 for i in range(1, 6)] print(squares) # [1, 4, 9, 16, 25] # With a filter condition evens = [x for x in ra...