# FOR SETS
a=set([1,2,3])
b=set([4,5,6])
print(a and b) #always prints right side value that is b here
print(a or b) #always prints left side value that is a here
print(b and a)#prints a as its on right
print(b or a)#prints b as its on left
#FOR BOOLEANS
print(False and 0) #prints False as it is on the left
print(0 and False) #prints 0 , same operator is used than why diff output
print(False or '') #prints '' as it is on the right
print('' or False) #prints False as now it is on the right
print(1 or True) #prints 1
print(True or 1) #prints True
print(True and 1)#prints 1
print(1 and True)#prints True
对于False类型的boolean,始终打印左侧值和/或始终打印右侧值。如果True类型为boolean,则相反。你知道吗
当应用于任何数量的集时,或给出最左边的值和最右边的值。为什么?你知道吗
Python参考资料回答了您的问题。https://docs.python.org/2/reference/expressions.html#boolean-operations
容器类型的值(如集合和列表)如果为空则视为false,否则视为true。你知道吗
我不认为这是由于左侧或右侧,但更多的是如何和-或评估。你知道吗
首先,在python中,0等于False,1等于True,但是可以重新分配True和False,但是默认情况下,0==0或0==False都是True。你知道吗
这就是说,您现在可以查看and-or运算符条件是如何计算的。你知道吗
总结: 和操作符总是在寻找一个假(0)值,如果他在第一个求值的参数上找到它,那么他就停止,但是如果他找到真或1,他就必须求值第二个条件,看看它是不是假。因为虚假的东西总是虚假的。这个表可能会帮你,看我什么时候有0(假)答案总是0(假)
或有点不同,但机制相同: 或会寻找他找到的第一个真的。因此,如果他首先发现False,他将计算第二个参数,如果他在第一个参数中发现True(1),那么他停止。 这里当你有一个1(真)答案总是1(真)
你可以看看其他运营商只是谷歌运营商真值表,你会有很多其他更详细的例子。你知道吗
例如:
相关问题 更多 >
编程相关推荐