โ† Back to Python Course
๐Ÿ“ฆ Lists & Dataยท20 minยทBeginner
๐Ÿ“‹

Lists

Collections of anything!

Learn how to store multiple items in a single list. Make a list of names, numbers, or anything else!

๐Ÿ“–

What we are learning

A list is a variable that can hold many values at once. Instead of making ten variables for ten names, you make one list that holds all ten. Lists keep things organized and easy to find!

๐Ÿ’ก Think of it like this:

Think of a list like a lunch tray with compartments. Each compartment holds a different food item, but they are all on the same tray. You can point to any compartment by its position.

๐ŸŒŸ

Why it matters

Lists are used everywhere โ€” shopping lists, playlists, high score tables, inventories. Any time you need to keep track of multiple things, a list is the right tool.

Where you see this in real life:

  • โœ“Music apps store your songs in a list (playlist)
  • โœ“Games store inventory items in a list
  • โœ“Schools store student names in a list
๐ŸŽฏ

By the end, you can:

  • 1.Create a list with multiple items
  • 2.Access items by their index
  • 3.Loop through a list with a for loop
๐Ÿ”ค

New words

listindexelementappend
๐Ÿ
If you made a list of your top 5 favorite foods, what would be at index 0?
๐Ÿค“

Fun Fact!

In Python, the first item in a list is at index 0, not 1! This is called "zero-based indexing" and most programming languages do it this way.

๐Ÿ“‹ What is a List?

A list is a variable that can hold many values at once. Instead of making ten variables for ten names, you make one list that holds all ten. Lists keep things organized and easy to find!

โœจ Create a List

Lists use square brackets []and items are separated by commas.

๐ŸCreate and print a list
main.py
โ— Output
Lists use square brackets []

๐Ÿ”ข Accessing Items by Index

Each item in a list has a position number called an index. Python starts counting from 0! So the first item is at index 0, the second at index 1, and so on.

๐ŸAccess list items by index
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿ”„ Loop Through a List

You can use a for loop to go through every item in a list!

๐ŸLoop through list items
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿ“ List Length

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

๐ŸCount items with len()
main.py
โ— Output
Click โ–ถ Run to see the output!
๐Ÿ
Try this: create a list of your 5 favorite movies. Print the first one and the last one. Then loop through them all!
๐Ÿง 

Quick Quiz!

+10 XP

If a list has 5 items, what is the index of the LAST item?

๐Ÿ
Finished the lesson? Click the button to mark it complete and earn XP!