Python Basics — Day 8 Lists in
Aspiring Full-Stack Developer | Python · Django · React · SQL | documenting my learning journey
Building skills in Python and full-stack development, with a focus on web apps and system design
Junior developer in training — Python, Django, React — preparing for a career in full-stack engineering
From Python basics to full-stack projects, sharing my progress as I grow into a developer
Future full-stack engineer | Learning in public: Python, APIs, Databases, and Web Development
01. What is a List?
A list is a data structure that stores multiple values in order.
Use square brackets
[ ]and separate values with commas.
fruits = ["Apple", "Banana", "Grape"]
numbers = [10, 20, 30, 40]
mixed = [1, "Hello", True, 3.14]
👉 Key features:
Ordered (index starts at 0)
Mutable (values can be changed)
02. Indexing and Slicing
fruits = ["Apple", "Banana", "Grape", "Strawberry"]
print(fruits[0]) # Apple
print(fruits[2]) # Grape
print(fruits[-1]) # Strawberry (last element)
print(fruits[1:3]) # ['Banana', 'Grape'] (index 1 to 2)
print(fruits[:2]) # ['Apple', 'Banana']
print(fruits[2:]) # ['Grape', 'Strawberry']
03. Modifying Lists
fruits = ["Apple", "Banana", "Grape"]
fruits[1] = "Mango" # Change value
print(fruits) # ['Apple', 'Mango', 'Grape']
04. Common List Methods
numbers = [3, 1, 4]
numbers.append(5) # Add to the end
print(numbers) # [3, 1, 4, 5]
numbers.insert(1, 100) # Insert at index 1
print(numbers) # [3, 100, 1, 4, 5]
numbers.remove(1) # Remove the value 1
print(numbers) # [3, 100, 4, 5]
numbers.pop() # Remove the last element
print(numbers) # [3, 100, 4]
print(numbers.index(100)) # 1 (index of the value)
print(numbers.count(4)) # 1 (count of the value)
numbers.sort() # Sort ascending
print(numbers) # [3, 4, 100]
numbers.reverse() # Reverse the order
print(numbers) # [100, 4, 3]
05. Lists with Loops
fruits = ["Apple", "Banana", "Grape"]
for f in fruits:
print(f)
# Print index and value together
for i, f in enumerate(fruits):
print(i, f)
06. 2D Lists
A list can contain other lists (useful for matrices or tables).
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(matrix[0][1]) # 2 (row 0, column 1)
print(matrix[2][2]) # 9
07. Practice Examples
Example 1: Replace an Item
fruits = ["Apple", "Banana", "Grape"]
fruits[1] = "Strawberry"
print(fruits)
Example 2: Sum of Numbers
numbers = [10, 20, 30, 40]
total = 0
for n in numbers:
total += n
print("Sum:", total)
Example 3: Find Maximum and Minimum
numbers = [3, 7, 2, 9, 5]
print("Maximum:", max(numbers))
print("Minimum:", min(numbers))