A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python-string-isspace-application/ below:

Python String isspace() Method - GeeksforGeeks

Python String isspace() Method

Last Updated : 02 Jan, 2025

isspace() method in Python is used to check if all characters in a string are whitespace characters. This includes spaces (' '), tabs (\t), newlines (\n), and other Unicode-defined whitespace characters. This method is particularly helpful when validating input or processing text to ensure that it contains only whitespace characters.

Let's understand this with the help of an example:

Python
s = "   "
print(s.isspace()) 
Explanation: Syntax of isspace() method

string.isspace()

Parameters Return Type String with mixed characters

Let's see what happens when the string contains non-whitespace characters:

Python
s = "Python is fun! "

print(s.isspace())  
Explanation: String with tabs and newlines

isspace() method considers tabs and newlines as whitespace characters:

Python
s = "\t\n"

print(s.isspace()) 
Explanation: What happens when the string is empty?

An empty string does not contain any characters, including whitespace.

Python
s = ""
print(s.isspace()) 
Explanation:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4