Can I print variables in a loop?

QuestionsQuestions8 SkillsProYour First Python LabSep, 22 2025
095

Yes, you can print variables in a loop in Python. Here's a simple example using a for loop:

names = ["Alice", "Bob", "Charlie"]

for name in names:
    print(name)

This will output:

Alice
Bob
Charlie

If you want to print multiple variables in a loop, you can do so by iterating over a list of tuples or using multiple lists. Here's an example with tuples:

people = [("Alice", 30), ("Bob", 25), ("Charlie", 35)]

for name, age in people:
    print(f"{name} is {age} years old.")

This will output:

Alice is 30 years old.
Bob is 25 years old.
Charlie is 35 years old.

Let me know if you have any more questions!

0 Comments

no data
Be the first to share your comment!