空 while 循环的 Python 语法 [英] Python syntax for an empty while loop

查看:32
本文介绍了空 while 循环的 Python 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个:

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

但我怀疑 continue 是不必要的?我要实现的目标的正确语法是什么?

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

推荐答案

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

这里使用 pass 语句:

This uses the pass statement :

pass 语句什么都不做.它可以在语法上需要语句但程序不需要操作时使用.

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

这篇关于空 while 循环的 Python 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆