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:
Convert String to int or Integer in Java
Python String lower()
Python Keywords and Identifiers
Python Objects and Classes
Python Program to Convert Celsius To Fahrenheit
Python Program to Compute all the Permutation of the String
Python Program to Differentiate Between type() and isinstance()
Python Program to Remove Punctuations From a String
Python print()
Python String partition()
Python Program to Create a Long Multiline String
Python Program to Check if a Number is Odd or Even
Python eval()
Python Tuple count()
Check if a String is a Palindrome in Java
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python format()
Python strftime()
Python next()
Python Program to Create Pyramid Patterns
Python Dictionary
Python input()
Python Program to Print Colored Text to the Terminal
Python String rstrip()
Python String rindex()
Python super()
Python Get Current time
Python Type Conversion and Type Casting
Python Set discard()
Python String index()
Python Program to Sort Words in Alphabetic Order
Python Program to Find LCM