Lists and dictionaries are the two data structures you will reach for constantly in real Python code - almost everything else builds on top of them.
Lists: ordered collections
fruits = ["apple", "banana", "mango"]
print(fruits[0]) # apple - indexing starts at 0
fruits.append("orange") # add to the end
print(len(fruits)) # 4
for fruit in fruits:
print(fruit)
List comprehensions
A compact way to build a new list from an existing one - genuinely idiomatic Python, worth learning early:
numbers = [1, 2, 3, 4, 5]
squares = [n * n for n in numbers]
print(squares) # [1, 4, 9, 16, 25]
evens = [n for n in numbers if n % 2 == 0]
print(evens) # [2, 4]
Dictionaries: key-value pairs
student = {"name": "Riya", "age": 21, "course": "Python"}
print(student["name"]) # Riya
student["age"] = 22 # update a value
student["grade"] = "A" # add a new key
for key, value in student.items():
print(key, "-", value)
Which one to use
Use a list when order matters and you are working with a simple sequence of items (a list of expenses, a queue of tasks). Use a dictionary whenever you are looking things up by a name or ID (a student's details, a product's price by its code). Most real programs end up using both together - like a list of dictionaries, one per record.