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?
In Python, to write empty functions, we use pass statement. pass is a special statement in Python that does nothing. It only works as a dummy statement. We can use pass in empty while statement also.
Syntax of while Loop in Python In the while loop, test expression is checked first. The body of the loop is entered only if the test_expression evaluates to True . After one iteration, the test expression is checked again. This process continues until the test_expression evaluates to False .
Empty while loopsAn empty while loop is a bad idea. This isn't the best approach but it is an acceptable one (in the right scenario). This ensures that you only perform the check at a reasonable interval. Note that the precise length of that interval is up to you to decide.
It can be used when a statement is required syntactically but the program requires no action.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With