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 Add Two Matrices
Python Numbers, Type Conversion and Mathematics
Python locals()
Python Program to Iterate Through Two Lists in Parallel
Python Set symmetric_difference()
Python divmod()
Python Program to Find the Largest Among Three Numbers
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Set pop()
Converting String to Stream of chars
Python Program to Catch Multiple Exceptions in One Line
Python Program to Capitalize the First Character of a String
Python Program to Get the File Name From the File Path
Python Set issuperset()
How to get current date and time in Python?
Python Program to Find Factorial of Number Using Recursion
Python String maketrans()
Python Dictionary
Python List
Python dir()
Python String rstrip()
Python Anonymous / Lambda Function
Python abs()
Python Program to Transpose a Matrix
Python Tuple index()
Python String swapcase()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Tuple count()
Python bin()
Python type()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Decorators