Python String isspace() Method
The Python isspace() method is a string method that returns True if all the characters in a string are whitespace characters, otherwise False. Whitespace characters are characters that are used for spacing, such as tabs (\t), spaces ( ), newlines (\n), etc.
Here are some examples of using the isspace() method:
# Example 1: A simple example of whitespace testing using isspace() method[^3^][4]
mystr = ' '
print(mystr.isspace())
# Prints True
mystr = '\t'
print(mystr.isspace())
# Prints True
mystr = 'tt'
print(mystr.isspace())
# Prints False
mystr = '\n\r'
print(mystr.isspace())
# Prints True
# Example 2: The isspace() method will return False even if one character is not a whitespace[^3^][4]
mystr = 'Hello World'
print(mystr.isspace())
# Prints False
mystr = ' Hello '
print(mystr.isspace())
# Prints False
If you have any questions about this code, you can drop a line in comment.
Comments
Post a Comment