【发布时间】:2020-10-26 10:35:48
【问题描述】:
我试图在 Python 中测试空字符串(空字符串应该是“Falsy”,因为他们写的是:How to check if the string is empty?)。但是我使用了一些不同的语法,并在以下比较中得到了奇怪的结果:
not(''); # result: True
not('hello'); # result: False
not('hello') == False; # result: True
not('hello') == True; # result: True - how is this result possible? (False == True: result must be False)
谢谢你的回答!
【问题讨论】:
-
FWIW,
()和;是非常多余的...... -
not否定布尔值。空字符串是 Falsy。不假是真的。 - 非空字符串是 Thruthy,不是 Truthy 是 flase。not没有功能 - ( ) 是你做的。not (hello) == True等于not ( "hello" == True)
标签: python string comparison