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:
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String startswith()
Python String isnumeric()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python oct()
Python Program to Check Prime Number
Python String lower()
Python classmethod()
Python List Comprehension
Python Program to Convert Kilometers to Miles
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python list()
Python property()
Python List pop()
Python Dictionary clear()
Python Sets
Python Program to Get Line Count of a File
Python Program to Display Powers of 2 Using Anonymous Function
Python Dictionary pop()
Python Program to Safely Create a Nested Directory
Python List
Python Functions
Python strftime()
Python frozenset()
Count Occurrences of a Char in a String
Java Program to Permute All Letters of an Input String
Python while Loop
Deep Learning with Python - Francois Cholletf
Python Program to Print Hello world!
Python Package
Python set()
Python abs()