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 String ljust()
Most commonly used String methods in Java
Python Inheritance
Python ord()
Python String maketrans()
Python globals()
Python String encode()
Python Objects and Classes
Python map()
Python Set pop()
Python Statement, Indentation and Comments
JavaScript Eval: run a code string
String Set Queries
Python String swapcase()
Python max()
Python Program to Calculate the Area of a Triangle
Python List clear()
Python String rjust()
Python del Statement
Python for Loop
Python Program to Generate a Random Number
Deep Learning in Python - LazyProgrammer
Python Decorators
Python Set intersection()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python super()
Python Program to Count the Number of Digits Present In a Number
Python String format()
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Differentiate Between type() and isinstance()
Convert String to int or Integer in Java
Python Strings