TalentJR

Lesson 11

Looping Through Lists

Process every item in a list

1What Are Lists?✨

Lists are used to store multiple items in a single variable. You can think of a list as a collection of things, like a shopping list or a list of your favorite games.

2Creating a List🎯

You can create a list by placing items inside square brackets [] and separating them with commas. Here's an example:

💻 code
games = ["Minecraft", "Among Us", "Fortnite"]

This creates a list called games with three video game titles.

3Looping Through a List💡

To process each item in a list, you can use a for loop. This allows you to perform an action for every item in the list. Here's how it works:

💻 code
for game in games:
    print(game)

This will print each game in the list one by one.

4Using the Index🚀

💻 code
You can also access items in a list using their index (position). Remember, Python uses zero-based indexing. Here's an example:
💻 code
for i in range(len(games)):
    print(f"Game {i + 1}: {games[i]}")

This prints each game with its number in the list.

5Modifying Items in a List🔍

You can change items in a list using their index. For example, if you want to replace "Fortnite" with "Roblox":

💻 code
games[2] = "Roblox"

6Now, if you print the list, it will show the updated games:⭐

💻 code
print(games)

7This will display: ['Minecraft', 'Among Us', 'Roblox']🧩

8What You'll Practice🎈

  • ✓ Looping through lists with for loops
  • ✓ Accessing items using indices
  • ✓ Modifying list items
  • ✓ Creating and using your own lists

Keep practicing! Looping through lists is a powerful way to work with data in Python.

🎯 Practice Challenges

Master Looping Through Lists by completing all 3 difficulty levels

🟢 EASY

Looping Through Lists - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Looping Through Lists - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Looping Through Lists - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Looping Through Lists? 🚀

Complete the challenges, take the quiz and keep your learning streak going!