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 String upper()
Python Set intersection()
Python *args and **kwargs
Python Recursion
Python datetime
Python Program to Count the Number of Occurrence of a Character in String
Python ascii()
Python Program to Make a Simple Calculator
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Print the Fibonacci sequence
Python object()
Generate a String
Python Dictionary
Python float()
Python Machine Learning - Sebastian Raschka
Python String expandtabs()
Python Program to Differentiate Between del, remove, and pop on a List
Python input()
Python List
Python iter()
Java Program to Permute All Letters of an Input String
Python List append()
Python Tuple
String Set Queries
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Program to Print Colored Text to the Terminal
Python setattr()
Python String rstrip()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python String split()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Dictionary items()