Python中Pass的用法

>>> help("pass")
The "pass" statement
********************

   pass_stmt ::= "pass"

"pass" is a null operation --- when it is executed, nothing happens.
It is useful as a placeholder when a statement is required
syntactically, but no code needs to be executed, for example:

   def f(arg): pass    # a function that does nothing (yet)

   class C: pass       # a class with no methods (yet)

Python帮助文档关于Pass的解释,简单翻译一下: “pass”是一个空操作,当它被执行时,什么也不会发生。当语法上需要语句,但不需要执行代码时,它被用作占位符。举一个简单的对比例子:

Python写法:

def f(arg): pass    # a function that does nothing (yet)

C语言写法:

void f(arg){             # a function that does nothing (yet)
;
}
时间: 2019年03月17日下午15:47  |  
作者:
2 COMMENTS
  1. 3周前
    知识共享网

    不错,谢谢分享

  2. 2019/03/23
    TTTT

    今天还听朋友说,让我学习Python

LEAVE A REPLY

loading