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 time Module
Python Type Conversion and Type Casting
Python Set symmetric_difference_update()
Python Anonymous / Lambda Function
Python pass statement
Deep Learning in Python - LazyProgrammer
Python Program to Trim Whitespace From a String
Python divmod()
Python Program to Find the Sum of Natural Numbers
Python Set pop()
Jackson – Marshall String to JsonNode
Python String istitle()
Python String rindex()
Python Program to Get the Class Name of an Instance
Java – String to Reader
Python Program to Count the Occurrence of an Item in a List
Encode a String to UTF-8 in Java
Python Directory and Files Management
Python String index()
Python Data Types
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Check If a String Is a Number (Float)
Python Program to Access Index of a List Using for Loop
Java InputStream to String
Python id()
Python Program to Get the Last Element of the List
Python String splitlines()
Python Custom Exceptions
Python ord()
Python Program to Create a Long Multiline String
Converting a Stack Trace to a String in Java