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.
다른 언어로
소스 콘텐츠 기반
zlliu.medium.com
핵심 통찰 요약
by Liu Zuo Lin 게시일 zlliu.medium.com 07-20-2024
https://zlliu.medium.com/i-recently-learn-2-strange-things-about-python-boolean-values-8e44f1e5735e더 깊은 질문