This article mainly introduces the details of Pythonpass and the related information of the instance code. For more information, see
Python pass usage:
- Empty statement do nothing
- Complete format
- Complete semantics
Take the if statement as an example. in c or c ++/Java:
If (true); // do nothingelse {// do something}
For Python, write as follows:
If true: pass # do nothingelse: # do something
1. Role of pass statements in functions
When you write a program, the execution of the statement is not completed yet. in this case, you can use the pass statement to hold the space, or use it as a tag, which is the code to be completed later. For example:
Def iplaypython (): pass
Define a function iplaypython, but the function body is not completed yet, and content cannot be left empty. Therefore, pass can be used to replace the occupied position.
2. Role of the pass statement in the loop
Pass is also commonly used to compile an empty body for a composite statement. for example, if you want an infinite loop of a while statement, no operation is required for each iteration. you can write it like this:
While True: pass
The above is just an example. In reality, it is best not to write such code, because the execution code block is pass, that is, nothing is done, and python will enter an endless loop.
Thank you for reading this article. I hope it will help you. thank you for your support for this site!