Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Python String isspace

by suresh

The Python isspace is one of the built-in String functions. This isspace function returns True if all the characters in a given string are whitespace characters. Otherwise, isspace function returns False.

In this section, we explain to you how to write an isspace Function in Python Programming with an example. The syntax of the isspace function is

String_Value.isspace()

Before we get into the examples of Python isspace function, let me show you the whitespace characters

  • ‘ ‘ – An empty space
  • \n – New Line
  • \t – Horizontal Tab
  • \v – Vertical Tab
  • \f – feed
  • \r – Carriage return

Python String isspace Example

In this example, we show how to find or check spaces in a string using this isspace function.

The first string is an empty string, but there is no empty space. The second statement has an empty space.

Within the third statement, we used a word with a combination of spaces. As you know, this Python function returns True only if all the characters are empty spaces. That’s why you see False.

# Python string isspace Example
 
str1 = ''
print(str1.isspace())
 
str2 = ' '
print(str2.isspace())
 
str3 = '  Python   '
print(str3.isspace())

OUTPUT

Python String isspace 1

Python isspace Example 2

In this example, we are using the isspace function against the Newline, horizontal tab, etc. These statements always return True. However, if you use them along with text, then the isspace String function returns false.

str1 = '\n'
print(str1.isspace())
 
str2 = '\t'
print(str2.isspace())
 
str3 = '\v'
print(str3.isspace())
 
str4 = '\f'
print(str4.isspace())
 
str5 = '\r'
print(str5.isspace())
 
str6 = '\n \t \v'
print(str6.isspace())

OUTPUT

Python isspace 2

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python Numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python Numpy concatenate
  • Python Numpy Array shape
  • Python Pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python Substring
  • Python Programming Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy