Python String isspace() Method

By Lenin Mishra

If you prefer to watch Youtube videos over reading blogs, check out our video on Python strings here.

Python String isspace() method

The isspace() method in Python returns True if all characters in your string are whitespace. If the string contains one or more non-white space characters, it returns False.

Each of the following characters are considered whitespace.

  1. - Empty space
  2. \n - Newline
  3. \r - Carriage return
  4. \f - feed
  5. \t - Horizontal tab
  6. \v - Vertical Tab
Syntax of isspace() method
string.isspace()

Returns True or False
Example

Code/Output

s = " "
print(s.isspace())
>>> True

s = "\n"
print(s.isspace())
>>> True

s = "\r"
print(s.isspace())
>>> True

s = "\t"
print(s.isspace())
>>> True

s = "\v"
print(s.isspace())
>>> True

s = "\f"
print(s.isspace())
>>> True

s = "\n \r \f"
print(s.isspace())
>>> True

s = "Pylenin"
print(s.isspace())
>>> False

Check out other commonly used Python string methods.

  1. How to create a string in Python?
  2. How to access characters in a Python string?
  3. How to replace characters in a string in Python?
  4. How to concatenate strings in Python?
  5. How to iterate through a string in Python?
  6. Check if a Substring is Present in a Given String in Python
  7. Escape sequences in Python String
  8. Python String Formatting - The Definitive Guide