bodacydo bodacydo - 27 days ago 7
Python Question

How to check if text is "empty" (spaces, tabs, newlines) in Python?

How can I test if the string is empty in Python?

For example,

is empty, so is

, so is

, etc.

Answer Source

"Return true if there are only whitespace characters in the string and there is at least one character, false otherwise."

Combine that with a special case for handling the empty string.

Alternatively, you could use

strippedString = yourString.strip()

And then check if strippedString is empty.