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:
True
if all characters in the string are whitespace charactersFalse
if 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 Differentiate Between type() and isinstance()
Python Program to Display Calendar
Python Variables, Constants and Literals
Python Program to Find Factorial of Number Using Recursion
Case-Insensitive String Matching in Java
Python Program to Find the Largest Among Three Numbers
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Display Fibonacci Sequence Using Recursion
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Recursion
Python Sets
Python float()
Jackson – Marshall String to JsonNode
Python Program to Convert Kilometers to Miles
Python Program to Count the Occurrence of an Item in a List
Python Dictionary keys()
Python Set remove()
Deep Learning with Python - Francois Cholletf
Python String isupper()
Python List clear()
Python Exception Handling Using try, except and finally statement
Python sleep()
Python chr()
Python File I/O Operation
Python Program to Shuffle Deck of Cards
Python Program to Find the Size (Resolution) of a Image
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python String center()
Python Set add()
Python datetime
Python repr()
Check if a String is a Palindrome in Java