YouTip LogoYouTip

Att String Isspace

body { font-family: "Microsoft YaHei", sans-serif; background-color: #f8f8f8; } .container { margin-top: 20px; } .sidebar { background-color: #f5f5f5; padding: 15px; border-radius: 5px; margin-bottom: 20px; box-shadow: 0 0 5px rgba(0,0,0,0.1); } .sidebar h3 { margin-top: 0; color: #333; } .sidebar a { display: block; padding: 5px 0; color: #007bff; text-decoration: none; font-size: 14px; } .sidebar a:hover { text-decoration: underline; } .content { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 5px rgba(0,0,0,0.1); } pre { background-color: #f0f0f0; padding: 15px; border-radius: 5px; overflow-x: auto; font-size: 14px; line-height: 1.6; } code { font-family: "Courier New", monospace; font-size: 14px; background-color: #f0f0f0; padding: 2px 5px; border-radius: 3px; } .footer { margin-top: 40px; text-align: center; color: #777; font-size: 14px; }

Python isspace() Method | .com

Python isspace() Method

The isspace() method checks whether all characters in the string are whitespace characters (including spaces, tabs, newlines, etc.), and returns True if so, otherwise False.

Syntax

str.isspace()

Parameters

No parameters required.

Returns

Returns True if all characters in the string are whitespace characters; otherwise, returns False.

Example

# Example 1: String with only whitespace
text1 = "   "
print(text1.isspace())  # Output: True

# Example 2: String with non-whitespace characters
text2 = "   hello   "
print(text2.isspace())  # Output: False

# Example 3: Empty string
text3 = ""
print(text3.isspace())  # Output: False

# Example 4: String with tab and newline
text4 = "tn"
print(text4.isspace())  # Output: True
        

Notes

  • Whitespace characters include space (' '), tab ('t'), newline ('n'), carriage return ('r'), form feed ('f'), and vertical tab ('v').
  • An empty string returns False because it contains no characters at all.
  • This method is useful for validating input data to check if a string is purely whitespace or empty.

Related Methods

  • isalnum() – Checks if all characters are alphanumeric.
  • isalpha() – Checks if all characters are alphabetic.
  • isdigit() – Checks if all characters are digits.
  • islower() – Checks if all characters are lowercase.
  • isupper() – Checks if all characters are uppercase.
Tip: Use isspace() when you want to verify that a string contains only whitespace or is completely empty.
← Att String IstitleAtt String Isnumeric β†’