Table of Contents
The isspace() method returns True if there are only whitespace characters in the string. If not, it return False.
Characters that are used for spacing are called whitespace characters. For example: tabs, spaces, newline, etc.
The syntax of isspace() is:
string.isspace()
1. isspace() Parameters
isspace() method doesn’t take any parameters.
2. Return Value from isspace()
isspace() method returns:
Trueif all characters in the string are whitespace charactersFalseif the string is empty or contains at least one non-printable character
3. Example 1: Working of isspace()
s = ' \t' print(s.isspace()) s = ' a ' print(s.isspace()) s = '' print(s.isspace())
Output
True False False
4. Example 2: How to use isspace()?
s = '\t \n'
if s.isspace() == True:
print('All whitespace characters')
else:
print('Contains non-whitespace characters')
s = '2+2 = 4'
if s.isspace() == True:
print('All whitespace characters')
else:
print('Contains non-whitespace characters.')
Output
All whitespace characters Contains non-whitespace characters
Related posts:
Python Program to Create Pyramid Patterns
Python Exception Handling Using try, except and finally statement
Python Dictionary values()
Python Program to Print Hello world!
String Initialization in Java
Python dict()
Python Program to Convert String to Datetime
Python Tuple index()
How to Get Started With Python?
Java – Reader to String
Python Tuple count()
Python Program to Check If a String Is a Number (Float)
Python List clear()
Python Program to Make a Flattened List from Nested List
Python del Statement
Python String format()
CharSequence vs. String in Java
Python while Loop
Python issubclass()
Python Program to Create a Long Multiline String
Format ZonedDateTime to String
Python sum()
Python Set update()
Python Object Oriented Programming
Python Numbers, Type Conversion and Mathematics
Python Set pop()
Python Data Structures and Algorithms - Benjamin Baka
Python Type Conversion and Type Casting
Python Program to Convert Decimal to Binary Using Recursion
Python strptime()
Python Dictionary update()
Python oct()