在C / C ++和Java中,我们可以编写如下的空函数
// C / C ++ / Java中的空函数
void fun(){}
然而在Python中,如果我们在Python中编写类似下面的内容,则会产生编译器错误。
# Incorrect empty function in Python
def
fun():
输出:
IndentationError:预期缩进块
在Python中,要编写空函数,我们使用pass语句。pass是Python中的一个特殊语句,它什么都不做。它只能作为虚拟语句。
# Correct way of writing empty function
# in Python
def
fun():
pass
我们也可以在空语句中使用pass。
# Empty loop in Python
mutex =
True
while
(mutex ==
True) :
pass
我们可以在空if语句中使用pass。
# Empty in if/else in Python
mutex =
True
if
(mutex ==
True) :
pass
else
:
print("False")
三个资料Q群下载不了也转发不了,先放这里Fine_tuning.zipLangChain.zipdata_clear.rar