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 id()
Python str()
Python Set clear()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Remove Duplicate Element From a List
Python Errors and Built-in Exceptions
Python Program to Split a List Into Evenly Sized Chunks
Converting String to Stream of chars
Python Program to Find Factorial of Number Using Recursion
Python super()
Python Set difference_update()
Python Set add()
Python Set intersection_update()
Python Dictionary popitem()
Python Program to Capitalize the First Character of a String
Python Generators
Python Iterators
Python eval()
Python Program to Slice Lists
Python Program to Print Hello world!
Python Program to Compute the Power of a Number
Python oct()
Python Program to Multiply Two Matrices
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Print all Prime Numbers in an Interval
Python Program to Check if a Key is Already Present in a Dictionary
Python frozenset()
Python String expandtabs()
Python List count()
Python Program to Check Armstrong Number
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Inheritance