一个小实验(x is y == True)
本帖最后由 hveagle 于 2022-10-15 10:48 编辑>>> def is_True(demo):
demo = demo + ' == True'
result = eval(demo)
if result == True:
print('Is True.')
else:
print('Is False.')
>>> x = 'ABC'
>>> y = 'ABC'
>>> is_True('x is y')
Is False.
>>> def is_True(demo):
demo = demo + ' == True'
result = eval(demo)
print(result)
>>> is_True('x is y')
False
>>> x is y == True
False
>>> x is y
True
>>> 运算符优先级的问题,==的优先级比is高,会先算'ABC' == True,在算'ABC' is False
>>> ('ABC' is 'ABC') == True
True x is y == True
x is False
False
页:
[1]