Python syntax for an empty while loop

泪湿孤枕 提交于 2019-12-06 16:34:59

问题


I have written this:

    while file.readline().startswith("#"):
        continue

But I suspect the continue is unnecessary? What is the correct syntax for what i'm trying to achieve?


回答1:


while file.readline().startswith("#"):
    pass

This uses the pass statement :

The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action.

http://www.network-theory.co.uk/docs/pytut/passStatements.html



来源:https://stackoverflow.com/questions/14797046/python-syntax-for-an-empty-while-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!