Usage of Python pass:
Take the if statement as an example, in c or c++/Java:
if(true) ; //do nothing else { //do something }
Corresponding to Python, it is written like this:
if true: pass #do nothing else: #do something
1 The role of the pass statement in the function
When you are writing a program, the execution statement part of the idea has not been completed. At this time, you can use the pass statement to occupy the place, or it can be used as a mark, which is the code to be completed later. For example:
def iplaypython(): pass
Define a function iplaypython, but the function body has not been completed yet, and it cannot be left empty without writing content, so you can use pass instead to occupy a place.
2 The role of pass statement in loop
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, which does not require any operation at each iteration, you can write 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, which means it is empty and does nothing. At this time, python will enter an infinite loop.
Thanks for reading, I hope it can help everyone, thank you for your support of this site!