【问题标题】:Are there any grounds not to use while in python [duplicate]在python中是否有任何理由不使用[重复]
【发布时间】:2013-07-28 19:57:24
【问题描述】:

我的一位老师警告我不要在 python 中使用while。这对我来说真的很奇怪,因为我没有找到任何关于为什么这样做的文章。你认为有什么根据?

【问题讨论】:

  • 糟糕的建议。我很想听听老师的解释!
  • for 循环同样有用,但有时您需要使用一段时间,这是个坏建议

标签: python while-loop do-while


【解决方案1】:

在每种情况下使用最适合您需要的控制语句。

“不要使用 while,只使用 for”这样的建议可以归结为“如果您知道的唯一工具是锤子,那么所有问题看起来都像钉子。”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2014-12-18
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    相关资源
    最近更新 更多