bodacydo bodacydo - 1 year ago 103
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download