这个问题在这里已经有了答案:
What is the purpose of the single underscore "_" variable in Python?
(5 个回答)
How can I get around declaring an unused variable in a for loop?
(10 个回答)
8 个月前关闭。
我正在看一些 tensorflow 的东西,我理解 for 循环,或者至少我认为我知道,但是我遇到了 for _ in range(20)
并且想知道在这种情况下 _ 的含义是什么。我习惯于 for x in range 或 for i in range 内容并理解这些内容,但无法理解我在下划线上阅读的内容
最佳答案
当您对函数返回的某些值不感兴趣时,我们使用下划线代替变量名。基本上,这意味着您对循环到目前为止运行的次数不感兴趣,只是它应该总体运行特定的次数。
关于python - 'for _ in range() 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66425508/