Python Full Tutorial — Part 6

Variables store single values. Real programs store collections of data. That is why data structures exist.

1. List

A list stores multiple values in order. Lists are mutable (changeable).

Creating a List

numbers = [10, 20, 30, 40]
print(numbers)
  
Access & Modify

numbers[0] = 99
print(numbers)
  
Common List Methods

numbers.append(50)
numbers.remove(20)
numbers.sort()
print(numbers)
  

Looping Through a List


for n in numbers:
    print(n)
  

2. Tuple

Tuple is like a list, but cannot be changed.

Tuple Example

coordinates = (10, 20)
print(coordinates[0])
  

Tuples are used when data must stay fixed.

3. Set

Set stores unique values. No duplicates. No order.

Set Example

numbers = {1, 2, 3, 3, 4}
print(numbers)
  
Set Operations

numbers.add(5)
numbers.remove(2)
print(numbers)
  

4. Dictionary

Dictionary stores data in key : value format.

Dictionary Example

student = {
    "name": "Rahul",
    "age": 21,
    "course": "Python"
}

print(student["name"])
  
Update Dictionary

student["age"] = 22
student["city"] = "Delhi"
print(student)
  

Looping Dictionary


for key, value in student.items():
    print(key, ":", value)
  

Real-World Example

User Database

users = [
    {"name": "Amit", "role": "admin"},
    {"name": "Neha", "role": "user"},
    {"name": "Ravi", "role": "user"}
]

for user in users:
    if user["role"] == "admin":
        print(user["name"], "has full access")
  

Which One to Use?

Key Takeaway

Every serious program uses data structures. If you skip this, you never grow beyond basics.

Next part: Functions — reusable logic & clean code.

Disclaimer:
This tutorial is for educational purposes only. Practice writing your own examples daily.