educative.io

Looping through a list

Why do you need to put the ): when you make a loop through a list?
And why does it say error if you take it out?

You shouldn’t need a closing parenthesis when looping through a list. For example, the following code loops through and prints out each float from the list:

float_list = [2.5, 16.42, 10.77, 8.3, 34.21]

for num in float_list: 
    print(num)

No parenthesis required. You do however need the colon (the two dots) to create a valid loop.

Let me know if this helps!

1 Like

now i understood, it´s just that when righting the premade for loop, they pressed enter unwillingly, so the ): missing was moved 1 line down

1 Like