The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example:
Pass语句不做任何事。只是语法要求,程序本身没有行为要求。例如:
>>>
>>> while True:
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...
This is commonly used for creating minimal classes:
通常使用pass语句来创建最小的类:
>>>
>>> class MyEmptyClass:
... pass
...
Another place pass can be used is as a place-holder for a function or conditional body when you are working on new code, allowing you to keep thinking at a more abstract level. The pass is silently ignored:
Pass语句的另一处应用是,当您处理新代码时,作为函数或条件体的占位符,从而使您能够在更抽象的层次上进行思考。
>>>
>>> def initlog(*args):
... pass # Remember to implement this!...
网友评论