What's the Pythonic way of checking whether a string is None, empty or has only whitespace (tabs, spaces, etc)? Right now I'm using the following bool check:
s is None or not s.strip()
..but was wondering if there's a more elegant / Pythonic way to perform the same check. It may seem easy but the following are the different issues I found with this:
isspace()returns False if the string is empty.- A bool of string that has spaces is
Truein Python. - We cannot call any method, such as
isspace()orstrip(), on aNoneobject.