My code:
a = 7
b = 5
print((a and b))
Output: 5
Why is the output 5? Doesn't logical operator gives True or False output? Why isnt it raising any errors ?
My code:
a = 7
b = 5
print((a and b))
Output: 5
Why is the output 5? Doesn't logical operator gives True or False output? Why isnt it raising any errors ?
In Python, the logical operator and returns the first operand if it evaluates to False, otherwise it returns the second operand.
In this case, both a and b are considered True because they are not equal to zero, so the expression (a and b) evaluates to the second operand, which is b with a value of 5.
So the output of print((a and b)) is 5.