Two pass statement Python

Explanation

Although mentioned in the secondary tutorial, pass statement is a reserved word choose to learn, but since has been involved in after-school exercises, I suggest it to master. Of course, this statement is relatively simple, but often.

Python role in pass sentence

Python pass is an empty statement, in order to maintain the integrity of the program structure. pass without doing anything, generally used as a placeholder statement. See the following particular specific application that is known.

Example 1: In the function definition

When writing a program, execute the statement part of the idea is not yet complete, then you can use the pass statement placeholder, may also be used as a marker, the code had to be completed later. Typically when writing function, such as the following:

def sample(*args):
    pass

In this example, the body of the function has not been determined, so as to be expressed, to be late for further improvement. If you do not pass the statement as a placeholder, then the definition of the function is unsuccessful.

Example 2: In the loop

In addition, pass also commonly used in the preparation of an empty compound statement is the body, for example, you want an infinite loop of while, no action is required at each iteration, you can write:

while True:
    pass

Of course, the above is just an example, in reality, it is best not to write code, because the code block to pass execution is, what do not empty, then the python will enter an infinite loop.

Guess you like

Origin blog.51cto.com/zhuxianzhong/2430342