Joh*_*ohn 0 python conditional function
因此,在一个函数中,我想测试该函数所期望的参数是否存在。如果有自变量,则执行此操作,如果没有从调用程序发送自变量,并且函数中未接收任何自变量,则执行此操作。
def do_something(calculate):
if calculate == something expected:
do this
elif calculate not sent to function:
do that
Run Code Online (Sandbox Code Playgroud)
那么,如果没有请自变量进入函数,我需要检查的逻辑测试/表达式是什么?
您可以将设置argument为None,并检查其是否通过,
def do_something(calculate=None):
if calculate is None:
# do that
return 'Whatever'
if calculate == "something expected":
# do this
return 'Whateverelse'
Run Code Online (Sandbox Code Playgroud)