-1

I have a variable called "string" in python. How can I check that my variable does not contain only whitespace, but has an actual character in it? If the variable contains only whitespace, I don't want to print it. If it has a character in it, then I want to print the variable.

Coder91092
  • 27
  • 5

1 Answers1

1

Use isspace():

string = ' '
if not string.isspace():
  print(string)
Code Pope
  • 5,075
  • 8
  • 26
  • 68