如果我输入** kwargs,我知道how to check。现在,我要检查传递给函数的参数的值。
def examplefunc(x,y,**kwargs):
print(kwargs['extraarg'])
if 'extraarg' in kwargs == True:
print(kwargs['extraarg'])
print("This is not printed")
if 'extraarg' in kwargs: print("This is printed")
examplefunc(3,2,extraarg=True)
输出:
是
已打印
为什么不打印This is not printed
? 'extraarg' in kwargs
是错误的。那么为什么要继续打印This is printed
?
我还尝试用if 'extraarg' in kwargs == True
替换行if 'extraarg' == True:
,但是输出仍然缺少This is not printed
。
答案 0 :(得分:-1)
def examplefunc(x,y,**kwargs):
print(kwargs['extraarg'])
if ('extraarg' in kwargs)==True
print(kwargs['extraarg'])
print("This is not printed")
if 'extraarg' in kwargs: print("This is printed")
if __name__ == "__main__":
examplefunc(3,2,extraarg=True)
True
True
This is not printed
This is printed