Lets Start Python Programming For Beginners to advanced. Lists β Storing Multiple Values, Lectures 9
π Lecture 9: Lists β Storing Multiple Values
π― Goal
By the end of this lecture, you will:
- Understand what a list is and why it’s useful.
- Be able to create, modify, and access items in a list.
- Use common list methods like
append()
,remove()
, andindex()
. - Loop through a list using a
for
loop.
π§ What Is a List?
A list is like a container that can hold multiple values at once.
You can think of it as a shopping list or a backpack β it holds many things in order.
π Example:
fruits = ["apple", "banana", "cherry"]
This list contains 3 items , and they stay in the order you put them in.
π¦ How to Create a List
Use square brackets [ ]
and separate items with commas.
Syntax:
my_list = [item1, item2, item3]
Examples:
numbers = [1, 2, 3, 4, 5]
names = ["Alice", "Bob", "Charlie"]
mixed = [1, "apple", True, 3.14]
π§ Kids Corner: A list is like your toy box β it can hold many different toys all together!

π’ Accessing Items in a List
Each item has an index (a number that tells its position).
Indexing starts at 0 , not 1.
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple
print(fruits[1]) # Output: banana
print(fruits[2]) # Output: cherry
You can also use negative indexes to go from the end:
print(fruits[-1]) # Output: cherry
print(fruits[-2]) # Output: banana
βοΈ Changing List Items
You can update any item by referring to its index:
fruits = ["apple", "banana", "cherry"]
fruits[1] = "blueberry"
print(fruits) # Output: ['apple', 'blueberry', 'cherry']
β Adding Items to a List
Use .append()
to add an item to the end of the list:
fruits = ["apple", "banana"]
fruits.append("orange")
print(fruits) # Output: ['apple', 'banana', 'orange']
Or use .insert()
to add at a specific position:
fruits.insert(1, "grape")
print(fruits) # Output: ['apple', 'grape', 'banana', 'orange']
β Removing Items from a List
Use .remove()
to remove a specific value:
fruits.remove("banana")
print(fruits) # Now banana is gone
Or use del
to remove by index:
del fruits[0]
print(fruits) # First item is gone
Use .pop()
to remove and get the last item:
last_fruit = fruits.pop()
print("Removed:", last_fruit)
π Looping Through a List
Use a for
loop to do something for each item:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
π Output:
apple
banana
cherry
This is super useful when working with large lists!
π§ͺ Try It Yourself!
Write code that:
- Creates a list of your favorite animals.
- Prints out each animal using a
for
loop. - Adds a new animal to the list.
- Removes one animal.
- Prints the updated list.
π‘ Sample Code:
animals = ["dog", "cat", "elephant"]
print("My favorite animals:")
for animal in animals:
print(animal)
animals.append("lion")
animals.remove("cat")
print("\nUpdated list:")
print(animals)
π§ Kids Corner
π§ Imagine you have a robot friend who loves collecting stickers.
It can keep all its stickers in a special sticker book β thatβs what a list is!
π€ Robot says:
I have 5 stickers: cat, dog, star, car, and rainbow!
π Challenge (Optional)
Make a grocery list app where the user can:
- Add an item.
- Remove an item.
- View the whole list.
Example:
grocery = []
while True:
action = input("What do you want to do? (add, remove, view, quit): ")
if action == "add":
item = input("Enter item to add: ")
grocery.append(item)
elif action == "remove":
item = input("Enter item to remove: ")
if item in grocery:
grocery.remove(item)
else:
print("Item not found!")
elif action == "view":
print("Your list:", grocery)
elif action == "quit":
print("Goodbye!")
break
else:
print("Invalid choice!")
π Summary
- A list stores multiple values in order.
- Use indexes to access or change items.
- Use
.append()
,.remove()
, anddel
to modify lists. - Loop through a list using
for
. - Lists help organize data and make programs more powerful.
Stay Updated
If you found this information useful, donβt forget to bookmark this page and Share and leave your feedback in the comment section below.
Python Programming For Beginners To Advanced
Python Programming For Beginners! Lecture 1
Python Programming! Variables and Data Types | Lectures 2
Python Programming! Input And Output | Lectures 3
Python Programming! Operators in Python Lectures 4
Python Programming! Conditional Statements Lectures 5
Python! Loops For and While | Lectures 6
Python! Building A Mini Game | Lectures 7
Python! Functions | Lectures 8
Python! Storing Multiple Values | Lectures 9Β