2023-10-01 13:02:22 +05:30
|
|
|
def is_upper(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are uppercase letters.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are uppercase letters, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_upper("HELLO")
|
|
|
|
True
|
|
|
|
>>> is_upper("Hello")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(ord(char) >= 65 and ord(char) <= 90 for char in string)
|
2023-10-01 12:52:36 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_lower(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are lowercase letters.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are lowercase letters, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_lower("hello")
|
|
|
|
True
|
|
|
|
>>> is_lower("Hello")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(ord(char) >= 97 and ord(char) <= 122 for char in string)
|
2023-10-01 12:42:59 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_alpha(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are alphabetical (letters).
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are letters, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_alpha("Hello")
|
|
|
|
True
|
|
|
|
>>> is_alpha("Hello123")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(char.isalpha() for char in string)
|
2023-10-01 12:52:36 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_alnum(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are alphanumeric (letters or digits).
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are letters or digits, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_alnum("Hello123")
|
|
|
|
True
|
|
|
|
>>> is_alnum("Hello 123")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(char.isalnum() for char in string)
|
2023-10-01 12:52:36 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_decimal(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are decimal digits.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are decimal digits, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_decimal("12345")
|
|
|
|
True
|
|
|
|
>>> is_decimal("12.345")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(char.isdigit() for char in string)
|
2023-10-01 12:52:36 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_space(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if all characters in the string are whitespace characters.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if all characters in the string are whitespace characters, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_space(" \\t\\n")
|
|
|
|
True
|
|
|
|
>>> is_space("Hello")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
return all(char.isspace() for char in string)
|
2023-10-01 12:52:36 +05:30
|
|
|
|
2023-10-01 13:02:22 +05:30
|
|
|
def is_title(string: str) -> bool:
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
|
|
|
Check if the string is in title case (first letter of each word is capital).
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Args:
|
|
|
|
string (str): The input string.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
2023-10-01 12:56:43 +05:30
|
|
|
Returns:
|
|
|
|
bool: True if the string is in title case, False otherwise.
|
2023-10-01 13:32:31 +05:30
|
|
|
|
|
|
|
Examples:
|
|
|
|
>>> is_title("This Is A Title Case String")
|
|
|
|
True
|
|
|
|
>>> is_title("This is Not a Title Case String")
|
|
|
|
False
|
2023-10-01 12:56:43 +05:30
|
|
|
"""
|
2023-10-01 13:02:22 +05:30
|
|
|
return string.istitle()
|
|
|
|
|
2023-10-01 13:32:31 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
import doctest
|
|
|
|
doctest.testmod()
|