Discusiones
Explora las últimas discusiones relacionadas con este dominio.
python - What is the meaning of 'for _ in range() - Stack Overflow
Main Post: python - What is the meaning of 'for _ in range() - Stack Overflow
For loop with undersore
Main Post: Hello, Can anyone tell me what this type of for loop means for _ in range(n):
Top Comment: Hello, Can anyone tell me what this type of for loop means for _ in range(n):
What is for _,?
Main Post: I’ve looked at youtube, searched the dev forum and dev hub, and still I cannot find anything about this. What is _, ? I tested around with it but it gave me many errors and I just stopped.
Top Comment: I’ve looked at youtube, searched the dev forum and dev hub, and still I cannot find anything about this. What is _, ? I tested around with it but it gave me many errors and I just stopped.
What do [] brackets in a for loop in python mean? - Stack Overflow
Main Post: What do [] brackets in a for loop in python mean? - Stack Overflow
Why do people use _ in for loops?
Main Post:
Saw this ik a video but don't understand
Top Comment:
It represents a 'junk' variable: It's assigned a value, but the value is not used in the code, so there's no point naming the variable.
For example:
for i in range(10): print('this doesn't use i')There's no point calling the loop variable i here as it's not used inside the loop at all. Instead, you can use _ to indicate this. This helps us demonstrate that the point of range here is to repeat an action 10 times, rather than count from 0-9.
for _ in range(10): print('this doesn't use i')