+180 XP
Next MissionLesson 8: Looping Through Lists
What if your backpack holds 100 items or you have a directory of alien species? Combining lists with for loops allows you to inspect every single item automatically.
Key Concepts to Remember:
- •for item in list: Python picks up each item one by one and executes your code block for it.
- •The "in" Keyword: Quickly checks if an item exists: if "Crystal Tiger" in aliens: True.
- •Item Counters: You can use a counter variable before the loop to number each item as you scan.
💻Scanning Items in a List (IDE Syntax Colors)
pets = ["Cat", "Dog", "Dragon"]
for pet in pets:
print(f"Adopt a {pet}!")
if "Dragon" in pets:
print("Found a mythical creature!")
💡 Loops through each pet and confirms Dragon is in the list.
💡 Pro Tip: The English word "in" works like a super-fast radar detector inside lists.