Course Content
Week 1: Getting Started
In week 1 the basis goal is to get started with the basics.
0/2
Week 2: Variables & Data Types
Variables are containers that computer programs use to store information pertinent to what that computer program will do. Data Types are the different types of Variables and how Python uses these variables when building logic
0/2
Week 3: Making Decisions
In both computer programs and the AI world, computer programs need a way to make decisions. Booleans and Conditionals provide a way to make this happen.
0/2
learning Python Programming and also Intro to Games

Lesson 9: Lists and Indexing

Topics Covered:

  • What are lists and how to create them
  • Accessing list items by index
  • Modifying lists (adding/removing items)
  • Looping through lists

What is a List?

A list is a collection of items stored in a specific order:

fruits = ["apple", "banana", "cherry"]

Accessing Items by Index

Indexing starts at 0, so the first item is at index 0:

print(fruits[0])  # apple
print(fruits[2])  # cherry

Changing Items in a List

fruits[1] = "blueberry"
print(fruits)  # ['apple', 'blueberry', 'cherry']

Adding Items

fruits.append("orange")
print(fruits)  # ['apple', 'blueberry', 'cherry', 'orange']

Removing Items

fruits.remove("apple")
print(fruits)  # ['blueberry', 'cherry', 'orange']

Length of a List

Use len() to find how many items are in a list:

print(len(fruits))  # 3

Looping Through a List

for fruit in fruits:
    print("I like", fruit)

Activity

  • Create a list of your favorite games or movies.
  • Print each item with a message.
  • Add a new item and remove one.
games = ["Minecraft", "Mario", "Zelda"]

for game in games:
    print("I love playing", game)

games.append("Among Us")
games.remove("Mario")

print("Updated list:", games)