Usage of Python Pass:
- Empty statement do nothing
- Guaranteed Format Integrity
- Ensure semantic integrity
Take the IF statement as an example, in C or C++/java:
if (true)
; Do nothing
else
{
//do something
}
This corresponds to Python:
If true: Pass
#do Nothing
else:
#do Something
The role of 1 pass statement in function
When you write a program, the execution of the statement part of the idea has not been completed, then you can use the PASS statement to occupy a bit, but also as a token, is to be completed after the code. Let's say this:
Define a function Iplaypython, but the function body part is not completed temporarily, and cannot empty not write content, so can use pass to replace occupies a position.
The function of 2 pass statement in circulation
Pass is also often used to write an empty body for a compound statement, for example, if you want an infinite loop of a while statement that requires no action for each iteration, you can write:
Just for example, it's best not to write code like this, because the execution code block does nothing for pass, where Python goes into a dead loop.
Thank you for reading, I hope to help you, thank you for your support for this site!