Skip to content

A. What Is a List?

โฑ๏ธ 5 min B. Creating a List โ†’

๐ŸŽฏ Learning Goals

By the end of this lesson, you'll be able to:

  • โ—‹ Understand what a list is
  • โ—‹ Understand why we use lists
  • โ—‹ Understand the difference between a list and a variable

Core Concepts

What is a list?

Lists is a way to store multiple items in a single variable.

๐Ÿ—„๏ธ Analogy: a chest of drawers

Just like Chest of drawersLike putting many things into a chest of drawers!

  • Chest of drawers = list
  • Drawer slot = index (0, 1, 2, ...)
  • Item = stored item

Variable vs. list

# Variable: stores only one value
fruit1 = "Apple"
fruit2 = "Banana"
fruit3 = "Orange"

# List: stores many values in one place
fruits = ["Apple", "Banana", "Orange"]

Advantages of a list

Advantages Description
Easy to manage Manage many objects as one
Using loops Easily process every item
Easy to add/remove Manage items dynamically

Using it in games

# Manage bullets
bullets = []

# Manage enemies
enemies = []

# Manage items
items = []

Example Code

# Fruit list
fruits = ["Apple", "Banana", "Orange"]

# Print the list
print(fruits)  # ['Apple', 'Banana', 'Orange']

# Check the count
print(len(fruits))  # 3

What Happens

Three fruits are stored in the list!


Quiz

Quiz: Why use a list
Why do you use a list to manage multiple bullets in a game?
Show Answer

Answer: B) To manage multiple items with a single variable

Using a list, you can easily manage multiple bullets, enemies, items, and more with a single variable!

Basic list practice:

fruits = ["์‚ฌ๊ณผ", "๋ฐ”๋‚˜๋‚˜", "์˜ค๋ Œ์ง€"] Given a list:

  • Symbol for making an empty list: my_list =
  • Multiple items are separated by it (e.g., ["์‚ฌ๊ณผ", "๋ฐ”๋‚˜๋‚˜"])
  • To check the number of items in the list (3): (fruits) โ†’ 3

๐Ÿ”ง Debug Clinic

Problem: managing multiple bullets is hard

โŒ Inefficient code

bullet1 = Entity(...)
bullet2 = Entity(...)
bullet3 = Entity(...)
Problem: Creating separate variables makes it hard to manage

โœ… Efficient code

bullets = []
bullets.append(bullet1)
bullets.append(bullet2)
Fix: Manage everything at once with a list!


Try Coding It Yourself

Take what you learned with the blocks and write it yourself in Python code!

Printing a list

Create a list and print it.

Example Answer
fruits = ['Apple', 'Banana', 'Orange']
print(fruits)
print(len(fruits))

Result: The list and its item count (3) are printed!


๐Ÿงฉ Key Takeaways

What you learned in this lesson:

Concept Description
Lists Store multiple items in a single variable
Square brackets [] to create a list
len() Check the number of items in a list
Advantages Easy management, loop usage, dynamic management

Review Checklist

  • [ ] Can you explain what a list is?
  • [ ] Do you know the difference between a variable and a list?
  • [ ] Do you understand why lists are used in games?

โฑ๏ธ 5 min B. Creating a List โ†’