python - 'for _ in range() 是什么意思

标签 python python-3.x machine-learning

这个问题在这里已经有了答案:





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/

相关文章:

python - 子进程和 psutil : how to get a list out of subprocess. check_output?

python - 如何将一个文件中列表中项目的匹配项保存到另一个文件

python - 在 Python 的 cmd 模块中隐藏命令

python-3.x - 在discord.py中获取附加图像的高度

machine-learning - 细胞/单元之间的 LSTM 连接(不是时间步长)

machine-learning - 卷积神经网络如何处理 channel

machine-learning - weka 机器学习教程

python - gensim.corpora.Dictionary 是否保存了词频?

python - 如何在 python 中模拟并仍然允许执行模拟函数的实际代码

python-3.x - 由于负索引查找,Keras 嵌入层中的 InvalidArgumentError