The logical operators and, or not only output bool types such as True and False, but also output numerical values, character strings, lists, etc. depending on the conditions. </ b>
The expressions x and y first evaluate x; if x is false, return the value of x; otherwise, evaluate the value of y and return the result. The expression x or y first evaluates x; returns the value of x if x is true; otherwise it evaluates the value of y and returns the result. 6. expression — Python 3.8.3 documentation
x = 5 # True
y = 0 # False
print(x and y)
# 0
print(x or y)
# 5
print(not x)
# False
x = 10 # True
y = 100 # True
print(x and y)
# 100
print(y and x)
# 10
print(x or y)
# 10
Reference site [https://note.nkmk.me/python-boolean-operation/:embed:cite]
Recommended Posts