我们知道,Java中&&可以造成&&可以造成短路与,&不会。
现在一起看看python中,如何体现?众所周知,python中没有&&的运算符,只有&和and
value = 0
if value!=0 and 1/value < 100:
print("The value is not too small")
else:
print("The value is too small")
out :
The value istoo small
and 实现了短路与
value = 0
if value!=0 & 1/value < 100:
print("The value is not too small")
else:
print("The value is too small")
out :
Traceback (most recent call last):
File "E:/PycharmProjects/Project/test/lazyTest.py", line 11, in <module>
if value!=0 & 1/value < 100:
ZeroDivisionError: division by zero
网友评论