def logical_xor(a, b): # for example, -1 and 1
print (a < 0) # evaluates to True
print (b < 0) # evaluates to False
print (a < 0 != b < 0) # EVALUATES TO FALSE! why??? it's True != False
return (a < 0 != b < 0) # returns False when it should return True
print ( logical_xor(-1, 1) ) # returns FALSE!
# now for clarification
print ( True != False) # PRINTS TRUE!
有人能解释一下正在发生什么吗?我正在尝试制作一行代码:
lambda a, b: (a < 0 != b < 0)
print(a*b < 0)
。 - David Hammenreturn math.copysign(1, a) != math.copysign(1, b)
- Jacob Krall