CODE PATH
PRO ACCOUNT

Master Code
On The Go

Learn. Practice. Build.

Quest 1 β€’ Lesson 3

πŸ“¦ Lists & Tuples

A list is a collection of items that can be changed (mutable). A tuple is like a list but cannot be changed (immutable). Both are fundamental for storing groups of data.

"Lists are great for to‑do lists – you can add, remove, or modify tasks. Tuples are for fixed data, like days of the week."
lists.py
fruits = ["apple", "banana", "cherry"]
mixed = [10, "hello", True, 3.14]

print(fruits) # Output: ['apple', 'banana', 'cherry']
print(fruits[0]) # Output: apple

🧠 List Basics

πŸ› οΈ Useful List Methods

.append() – adds an item to the end.
fruits.append("orange") # fruits now has 4 items
.remove() – removes the first occurrence of an item.
fruits.remove("banana")
len() – returns the number of items.
print(len(fruits)) # Output: 3

πŸ“Œ Tuples – Immutable Lists

Tuples are created with ( ) (parentheses). They cannot be changed after creation.

days = ("Mon", "Tue", "Wed")
coordinates = (10, 20)

# days.append("Thu") would cause an error – tuples are immutable!

Use tuples for data that should never change (e.g., weekdays, fixed settings).

✨ Challenge: Build a Shopping List

Create a list called shopping with 3 items. Then:
1. Append a fourth item.
2. Remove the second item.
3. Print the final list.

shopping = ["milk", "bread", "eggs"]
shopping.append("butter")
shopping.remove("bread")
print(shopping)

πŸ” Try It Mentally

What would be the output of this code?

numbers = [1, 2, 3]
numbers.append(4)
print(numbers[2])
Reveal answer

Output: 3 (index 2 is the third item)

❀️ Support Free Education

This course is 100% free. If it helps you, consider buying me a coffee.

β˜• Buy Me a Coffee

➑️ Ready for more?

Next lesson: Conditional Statements (if/else) – control the flow of your program.

Continue to Lesson 1.4 β†’

(Coming soon – check back or buy Pro Pack for instant access)