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
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.
"_" means you won't need a name for a var that will not be used.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With