我知道how to check如果我输入**kwargs存在。现在我要检查传递给函数的参数的值。你知道吗
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)
输出:
True
This is printed
为什么This is not printed
不打印?'extraarg' in kwargs
为false。那么为什么要继续打印This is printed
?你知道吗
我还尝试用if 'extraarg' == True:
替换if 'extraarg' in kwargs == True
行,但是输出仍然缺少This is not printed
。你知道吗
输出:
相关问题 更多 >
编程相关推荐