How to use the Python pass:
Empty statement does nothing
Guaranteed Format Complete
Guaranteed Semantic Integrity
Take the IF statement as an example, in C or C++/java:
if (true); Do nothingelse{ //do something}
This is what Python should write:
If true: pass #do nothingelse: #do Something
1 function of pass statements in functions
When you are writing a program, the execution of the statement part of the idea is not complete, you can use the PASS statement to occupy a bit, can also be used as a token, is to be completed after the code. such as the following:
Def iplaypython (): Pass
A function iplaypython is defined, but the function body part is not finished yet, and cannot be empty without writing the content, so it is possible to replace the position with a pass.
2 The function of the pass statement in the loop
Pass is also often used to write an empty body for a compound statement, for example, you want an infinite loop of a while statement, no action is required for each iteration, you can write:
While True: Pass
Just for example, in reality it is best not to write this code, because the code block for the pass is the empty do nothing, then Python will enter the dead loop.
Thank you for reading, hope to help everyone, more relevant articles please pay attention to topic.alibabacloud.com (www.php.cn)!