The author recently learned two interesting and unexpected things about Python boolean values:
print(True == 1) # True
print(False == 0) # True
print(True is 1) # False
print(False is 0) # False
print(True + True) # 2
print(True + True + True) # 3
ls = [True, True, False, True, False, False, True, False]
print(sum(ls)) # 4
These behaviors, while strange and unintuitive, can be useful in certain situations. The author suggests readers check out their Substack post for more cool Python boolean-related insights.
To Another Language
from source content
zlliu.medium.com
Key Insights Distilled From
by Liu Zuo Lin at zlliu.medium.com 07-20-2024
https://zlliu.medium.com/i-recently-learn-2-strange-things-about-python-boolean-values-8e44f1e5735eDeeper Inquiries