30

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

ShadowXL
  • 433
  • 1
  • 4
  • 6
  • 8
    By convention `_` means to other developers that the variable is unused. On that note linters such as pylint will not emit "unused variable" warnings for this symbol. – Cory Kramer Mar 01 '21 at 16:04

1 Answers1

39

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.

Harsh Chaturvedi
  • 679
  • 6
  • 13
  • 47
    *"it means you are not interested in how many times the loop is run"* is not true. I think a better sentence would be *"we don't care about the iterator value, just that it should run some specific number of times".* – Ted Klein Bergman Mar 01 '21 at 16:10