Print Through A List

Print Through A List

This is the syntax for a super simple Python program that takes a list and prints out each out item in the list using a for loop.

For 'pizzazz' I used f-string syntax to print more than just the item in the list, but rather a phrase "printing number __!". The curly brackets hold the place of the variable to be used in that place of the printed text.

# list of numbers
numbers = ['1','2','3','4','5']

# for loop that goes through each item in list
for number in numbers:
    print(f"printing number {number}!")

Output

printing number 1!
printing number 2!
printing number 3!
printing number 4!
printing number 5!

I love how For Loops in Python lets you create a new variable in the command. It helps make the code that much easier to understand when I can say to myself "For each number in the list of numbers..." and have that be able to be used in my code.