Python String Checking
The following code demonstrates Python string checking:
Examples
# Filename : test.py
# author by : www.example.com
# Test example one
print("Test example one")
str = "example.com"
print(str.isalnum()) # Check if all characters are digits or letters
print(str.isalpha()) # Check if all characters are letters
print(str.isdigit()) # Check if all characters are digits
print(str.islower()) # Check if all characters are lowercase
print(str.isupper()) # Check if all characters are uppercase
print(str.istitle()) # Check if all words start with an uppercase letter, like a title
print(str.isspace()) # Check if all characters are whitespace characters, \t, \n, \r
print("------------------------")
# Test example two
print("Test example two")
str = "example"
print(str.isalnum())
print(str.isalpha())
print(str.isdigit())
print(str.islower())
print(str.isupper())
print(str.istitle())
print(str.isspace())
# author by : www.example.com
# Test example one
print("Test example one")
str = "example.com"
print(str.isalnum()) # Check if all characters are digits or letters
print(str.isalpha()) # Check if all characters are letters
print(str.isdigit()) # Check if all characters are digits
print(str.islower()) # Check if all characters are lowercase
print(str.isupper()) # Check if all characters are uppercase
print(str.istitle()) # Check if all words start with an uppercase letter, like a title
print(str.isspace()) # Check if all characters are whitespace characters, \t, \n, \r
print("------------------------")
# Test example two
print("Test example two")
str = "example"
print(str.isalnum())
print(str.isalpha())
print(str.isdigit())
print(str.islower())
print(str.isupper())
print(str.istitle())
print(str.isspace())
The output of the above code is:
测试实例一 False False False True False False False ------------------------ 测试实例二 True True False True False FalseOther Extensions
Python3 Examples