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 Split a List Into Evenly Sized Chunks
Python Modules
Python Input, Output and Import
Python String count()
Python Program to Catch Multiple Exceptions in One Line
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String rstrip()
Python Set difference_update()
Python Set issuperset()
Python Program to Print Colored Text to the Terminal
Python datetime
Python Inheritance
Python break and continue
Python String zfill()
How to Get Started With Python?
Java InputStream to String
Python Tuple index()
Python Program to Parse a String to a Float or Int
Python String rindex()
Python String rjust()
Python Operators
Python setattr()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python String maketrans()
Java String Conversions
Python String rsplit()
Python List
Python List remove()
Python Program to Sort Words in Alphabetic Order
String Set Queries
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...