3. Introducing Lists
1. Simple Definition & Meaning
A List is exactly what it sounds like! It’s a way to store multiple items in a single variable. Instead of having 5 different boxes, you have one big box with 5 compartments.
2. Real-World Examples
- Example 1: Think of a grocery shopping list. Instead of remembering "Apples", "Milk", and "Bread" separately, you put them all on one piece of paper!
- Example 2: A train with many carriages. The whole train is the List, and each carriage holds a different item.
3. Important Points
- Lists are written with square brackets
[]. Example:fruits = ["apple", "banana", "cherry"]. - The items in a list have numbers called Index. But remember, Python starts counting from 0, not 1!
- So, the first item is at index 0, the second is at index 1.
📝 Exam Notes (Quick Revision)
- Syntax:
my_list = [item1, item2, item3] - Zero-Indexed: The first element is always accessed with
my_list[0]. - Mutable: You can change, add, or remove items after creating the list.