4.5. pass Statements

2019-08-28  本文已影响0人  赵敏是程序媛

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!...

上一篇 下一篇

猜你喜欢

热点阅读