Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of 'for _ in range() [duplicate]

I'm looking at some tensorflow stuff and I understand for loops or atleast I think I do, however I came across for _ in range(20) and was wondering what is the meaning of the _ in this case. I am used to for x in range or for i in range stuff and understand those but haven't been able to understand what i've read on the underscore

like image 583
ShadowXL Avatar asked Mar 01 '21 16:03

ShadowXL


People also ask

What is for _ in range?

Basically it means you are not interested in how many times the loop is run till now just that it should run some specific number of times overall. Follow this answer to receive notifications.

What does _ mean in for loop?

"_" means you won't need a name for a var that will not be used.

What does _ mean in for loop Python?

Python automatically stores the value of the last expression in the interpreter to a particular variable called "_." You can also assign these value to another variable if you want.

What is for in range Python?

The range() function provides a sequence of integers based upon the function's arguments. Additional information can be found in Python's documentation for the range() function. The start argument is the first value in the range. If range() is called with only one argument, then Python assumes start = 0 .


1 Answers

When you are not interested in some values returned by a function we use underscore in place of variable name . Basically it means you are not interested in how many times the loop is run till now just that it should run some specific number of times overall.

like image 54
Harsh Chaturvedi Avatar answered Oct 17 '22 02:10

Harsh Chaturvedi