Search⌘ K
AI Features

Solution: Favorite Things

Explore how to use for loops in Python to iterate over a list of favorite activities. Understand how to access each item one at a time and display it in a sentence using the print function. This lesson helps you practice looping through lists to automate repetitive tasks in your programs.

We'll cover the following...

This program uses a for loop to go through a list of favorite activities and print each one in a sentence.

  • favorites is a list, a collection of items stored in square brackets [ ].

  • The for loop goes through each element in the list, one at a time.

  • Each time the loop runs, the variable item takes the next value from the list.

  • The print() statement displays a sentence using that item.

Python
favorites = ["reading", "coding", "travel"]
for item in favorites:
print("One of my favorite things is", item)