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 Safely Create a Nested Directory
Python format()
Python min()
Python String rstrip()
Python memoryview()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Measure the Elapsed Time in Python
Python Program Read a File Line by Line Into a List
Python Set symmetric_difference_update()
Python list()
Java InputStream to String
Python Program to Convert Two Lists Into a Dictionary
JavaScript Methods of RegExp and String
Python Program to Swap Two Variables
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Find HCF or GCD
Python String isalnum()
Python List insert()
Python Program to Convert Bytes to a String
Python List reverse()
Python Program to Find ASCII Value of Character
Python Program to Convert Celsius To Fahrenheit
Python getattr()
Python Program to Find Numbers Divisible by Another Number
Python String startswith()
Python any()
Java InputStream to String
Python String partition()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Converting a List to String in Java
Python Global Keyword