pass
在python中基本上什么也不做,但与注释不同的是,它不会被解释器忽略。所以你可以在很多地方利用它,让它成为一个占位符:
1:可以在课堂上使用
class TestClass:
pass
2:可以在循环和条件语句中使用:
if (something == true): # used in conditional statement
pass
while (some condition is true): # user is not sure about the body of the loop
pass
3:可用于函数:
def testFunction(args): # programmer wants to implement the body of the function later
pass
通过
主要用于程序员现在不想给出实现,但仍然想创建一个特定的类/函数/条件语句,以便以后使用。由于python解释器不允许空白或未实现的类/函数/条件语句,因此它会给出一个错误:
缩进错误:需要缩进的块
通过
可以在这种情况下使用。