空字符串

基本类型 / 字符串

# 空字符串字面量
some_empty_string = ""
# 凭空构造
another_empty_string = str()

# 空字符串为假值
is_empty = not some_empty_string
# is_empty is True
is_another_empty = not another_empty_string
# is_another_empty is True

# 空格不算空
spaces = "   "
spaces_empty = not spaces
# spaces_empty is False

# strip() 后它就成了空白
spaces_blank = not spaces.strip()
# spaces_blank is True

print(f"{is_empty = }")
print(f"{is_another_empty = }")
print(f"{spaces_empty = }")
print(f"{spaces_blank = }")