For loop with undersore

Hello,
Can anyone tell me what this type of for loop means for _ in range(n):

It’s just a variable name like any other. Sometimes people use this name to mean that the value is not important, i.e., it won’t be used inside the loop. But Python does not care about such a meaning.

1 Like

The underscore is a convention meaning “doesn’t matter what this is”. So the loop will iterate n times, but without making use of a classic iteration counter. Technically the iteration counter does still exist, but if you’re going to actually USE it, you’d rename it to something else (eg i).

3 Likes

Hi, Can you please tell me what the star means in this line name, *line = input().split()

>>> *line = input().split()
SyntaxError: starred assignment target must be in a list or tuple

The Symbol index, which you should take a look at, has an entry for * (Asterisk) which includes subentry in assignment target list. If that is unclear, ask on a new thread so others can find the question.

2 Likes

The loop variable is an underscore (_), which is commonly used when the variable itself isn’t crucial. The loop will repeat as many times as range(n) specifies.