Mots clés : pythonstringcomparison-operatorspython
94
if not myString:
80
if not some_string:
if some_string:
75
if not my_string:
>>> bool("") False >>> bool(" ") True >>> bool(" ".strip()) False
67
def isBlank (myString): if myString and myString.strip(): #myString is not None AND myString is not empty or blank return False #myString is None OR myString is empty or blank return True
def isNotBlank (myString): if myString and myString.strip(): #myString is not None AND myString is not empty or blank return True #myString is None OR myString is empty or blank return False
def isBlank (myString): return not (myString and myString.strip()) def isNotBlank (myString): return bool(myString and myString.strip())
55
def is_not_blank(s): return bool(s and not s.isspace())
print is_not_blank("") # False print is_not_blank(" ") # False print is_not_blank("ok") # True print is_not_blank(None) # False