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 Compute all the Permutation of the String
Python while Loop
Python Program to Display Calendar
Python super()
Python Program to Trim Whitespace From a String
Python Inheritance
Python String upper()
Python String lower()
Python Set symmetric_difference_update()
Why String is Immutable in Java?
Python delattr()
Python List copy()
Python exec()
Python Function Arguments
Python String zfill()
Python bin()
Python tuple()
Python Program to Randomly Select an Element From the List
Python Program to Add Two Matrices
Python for Loop
Python round()
Python Program to Make a Flattened List from Nested List
Split a String in Java
Python object()
Python Program to Differentiate Between del, remove, and pop on a List
Python Program to Find HCF or GCD
Python Dictionary copy()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Java – String to Reader
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Set add()