DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on

๐Ÿคญ `zip` Python Quiz Of The Day

The zip() function in Python is a powerful tool but often misunderstood by beginners. It's used to combine elements from multiple iterables (like lists, tuples) into tuples.

Quiz

Which one of these code samples correctly demonstrates the use of the zip() function in Python?

Sample 1

names = ['Alice', 'Bob', 'Charlie']
ages = [25, 30, 35]

for name, age in zip(names, ages):
    print(f"{name} is {age} years old.")
Enter fullscreen mode Exit fullscreen mode

Sample 2

names = ['Alice', 'Bob', 'Charlie']
ages = [25, 30, 35]

for i in range(len(names)):
    print(f"{names[i]} is {ages[i]} years old.")

Enter fullscreen mode Exit fullscreen mode

Post answer that you think is correct or just try it in the REPL!

Follow me to learn ๐Ÿ Python in 5-minute a day fun quizzes!

Top comments (2)

Collapse
 
aj-esh profile image
Ajeesh Sunil • Edited

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

For both samples

Collapse
 
vladignatyev profile image
Vladimir Ignatev

You are right. But the second example does not involve zip at all! It demonstrates one of the powers of zip! ๐Ÿ˜„