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:
String Hashing
Python str()
Python Generators
Python Data Structures and Algorithms - Benjamin Baka
Python format()
Python Program to Count the Number of Each Vowel
Python Program to Count the Number of Digits Present In a Number
Python Global, Local and Nonlocal variables
JavaScript Eval: run a code string
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
String Processing with Apache Commons Lang 3
Python String strip()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Package
Python Program to Differentiate Between del, remove, and pop on a List
Python List sort()
Reading an HTTP Response Body as a String in Java
Python Set issubset()
Python String isnumeric()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python String expandtabs()
Python Program to Find LCM
Java – Generate Random String
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Find Armstrong Number in an Interval
Python Program to Find the Sum of Natural Numbers
Python hash()
Python Set isdisjoint()
Python Errors and Built-in Exceptions
Python Program to Create a Countdown Timer