Answers:
“如果字符串中只有空格字符并且至少有一个字符,则返回true,否则返回false。”
结合特殊情况处理空字符串。
或者,您可以使用
strippedString = yourString.strip()然后检查strippedString是否为空。
None,或''
                    if len(str) == 0 or str.isspace():
                    对于那些希望像Apache StringUtils.isBlank或Guava Strings.isNullOrEmpty这样的行为的用户:
if mystring and mystring.strip():
    print "not blank string"
else:
    print "blank string"我使用以下内容:
if str and not str.isspace():
  print('not null and not empty nor whitespace')
else:
  print('null or empty or whitespace')与c#字符串静态方法类似isNullOrWhiteSpace。
def isNullOrWhiteSpace(str):
  """Indicates whether the specified string is null or empty string.
     Returns: True if the str parameter is null, an empty string ("") or contains 
     whitespace. Returns false otherwise."""
  if (str is None) or (str == "") or (str.isspace()):
    return True
  return False
isNullOrWhiteSpace(None) -> True // None equals null in c#, java, php
isNullOrWhiteSpace("")   -> True
isNullOrWhiteSpace(" ")  -> Truereturn (str is None) or (str == "") or (str.isspace())
                    None和""都falsy,所以你可以:return not str or  str.isspace()
                    
U+00A0或,则此操作在Python 2.4中失败ALT+160。在Python 2.7中看起来固定。