Complete List of Python String Validation Methods
Python provides several built-in string methods to check if a string meets certain criteria. These methods return True or False and are useful for input validation, data cleaning, and text processing.
1. Case Checking Methods
| Method | Description | Example |
|---|---|---|
isupper() | Checks if all characters are uppercase | "HELLO".isupper() โ True |
islower() | Checks if all characters are lowercase | "hello".islower() โ True |
istitle() | Checks if the string is in title case (first letter of each word capitalized) | "Python Code".istitle() โ True |
2. Character Type Validation
| Method | Description | Example |
|---|---|---|
isalpha() | Checks if all characters are alphabetic (a-z, A-Z) | "Python".isalpha() โ True |
isdigit() | Checks if all characters are digits (0-9) | "123".isdigit() โ True |
isnumeric() | Checks if all characters are numeric (includes Unicode numbers) | "โ
ง".isnumeric() โ True |
isdecimal() | Checks if all characters are decimal (0-9 and Unicode decimal numbers) | "12.5".isdecimal() โ False |
isalnum() | Checks if all characters are alphanumeric (letters or digits) | "Python123".isalnum() โ True |
3. Whitespace & Format Checking
| Method | Description | Example |
|---|---|---|
isspace() | Checks if all characters are whitespace ( , \t, \n, etc.) | " \t\n".isspace() โ True |
isprintable() | Checks if all characters are printable (non-printable chars like \x00 return False) | "Hello".isprintable() โ True |
4. ASCII & Unicode Validation
| Method | Description | Example |
|---|---|---|
isascii() | Checks if all characters are ASCII (Unicode code point โค 127) | "Python".isascii() โ True |
isidentifier() | Checks if the string is a valid Python identifier (variable name) | "var_name".isidentifier() โ True |
5. Specialized Checks
| Method | Description | Example |
|---|---|---|
startswith(prefix) | Checks if the string starts with prefix | "Hello".startswith("He") โ True |
endswith(suffix) | Checks if the string ends with suffix | "world".endswith("ld") โ True |
Summary Table of All Methods
| Method | Returns True If |
|---|---|
isupper() | All uppercase letters |
islower() | All lowercase letters |
istitle() | Title case (each word capitalized) |
isalpha() | Only alphabetic letters (a-z, A-Z) |
isdigit() | Only digits (0-9) |
isnumeric() | Only numeric characters (includes Unicode) |
isdecimal() | Only decimal digits (0-9 and Unicode decimals) |
isalnum() | Only alphanumeric (letters or digits) |
isspace() | Only whitespace ( , \t, \n) |
isprintable() | All characters are printable |
isascii() | All characters are ASCII (Unicode โค 127) |
isidentifier() | Valid Python identifier (variable name) |
startswith(prefix) | String starts with prefix |
endswith(suffix) | String ends with suffix |
1. s.isupper()
Checks if all characters in the string are uppercase letters.
Examples:
python
print("HELLO".isupper()) # True
print("Hello".isupper()) # False (contains lowercase 'e')
print("123ABC".isupper()) # True (numbers allowed, but letters must be uppercase)
2. s.islower()
Checks if all characters in the string are lowercase letters.
Examples:
python
print("hello".islower()) # True
print("Hello".islower()) # False (contains uppercase 'H')
print("123abc".islower()) # True (numbers allowed, but letters must be lowercase)
3. s.istitle()
Checks if the string is in title case (first letter of each word capitalized, rest lowercase).
Examples:
python
print("Python Programming".istitle()) # True
print("python programming".istitle()) # False
print("Python programming".istitle()) # False (second word not capitalized)
4. s.isalnum()
Checks if the string contains only alphanumeric characters (letters a-z, A-Z, and digits 0-9).
Examples:
python
print("Python123".isalnum()) # True
print("Python_123".isalnum()) # False (contains underscore)
print("123".isalnum()) # True
print("Python".isalnum()) # True
5. s.isalpha()
Checks if the string contains only alphabetic characters (letters a-z, A-Z).
Examples:
python
print("Python".isalpha()) # True
print("Python123".isalpha()) # False (contains digits)
print("123".isalpha()) # False
6. s.isspace()
Checks if the string contains only whitespace characters ( , \t, \n, etc.).
Examples:
python
print(" ".isspace()) # True
print("\t\n".isspace()) # True
print("Hello".isspace()) # False
7. s.isascii()
Checks if all characters in the string are ASCII (Unicode code point <= 127).
Examples:
python
print("Python".isascii()) # True
print("Pythรถn".isascii()) # False (contains 'รถ', a non-ASCII character)
print("123#!".isascii()) # True
Summary Table
| Method | Checks For | Example (True) | Example (False) |
|---|---|---|---|
isupper() | All uppercase letters | "HELLO" | "Hello" |
islower() | All lowercase letters | "hello" | "Hello" |
istitle() | Title case (each word capitalized) | "Python Code" | "python code" |
isalnum() | Only letters & digits | "Python123" | "Python_123" |
isalpha() | Only letters | "Python" | "Python123" |
isspace() | Only whitespace | " \t\n" | "Hello" |
isascii() | Only ASCII characters | "Python" | "Pythรถn" |
These methods are useful for input validation, data cleaning, and text processing. Let me know if you need more examples! ๐
Unicode & ASCII-Based String Validation Methods in Python
These methods help determine if a string contains specific types of characters (digits, numbers, decimals, or alphanumeric). They are particularly useful when working with Unicode characters beyond standard ASCII (0-127).
1. isdigit()
Checks if all characters are digits (0-9 and some Unicode digits like superscripts).
Examples:
python
print("123".isdigit()) # True (ASCII digits)
print("ยฒยณโด".isdigit()) # True (Unicode superscripts)
print("12.5".isdigit()) # False (decimal point not allowed)
print("เฅงเฅจเฅฉ".isdigit()) # True (Devanagari digits)
2. isnumeric()
Checks if all characters are numeric (digits, fractions, Roman numerals, etc.).
Examples:
python
print("123".isnumeric()) # True (ASCII digits)
print("โ
ง".isnumeric()) # True (Roman numeral 8)
print("ยพ".isnumeric()) # True (Vulgar fraction)
print("12.5".isnumeric()) # False (decimal point not numeric)
3. isdecimal()
Checks if all characters are decimal digits (0-9 and some Unicode decimals).
Examples:
python
print("123".isdecimal()) # True (ASCII digits)
print("เฅงเฅจเฅฉ".isdecimal()) # True (Devanagari digits)
print("ยฒยณโด".isdecimal()) # False (superscripts are digits but not decimals)
print("12.5".isdecimal()) # False (decimal point not allowed)
4. isalnum()
Checks if all characters are alphanumeric (letters a-z, A-Z, or digits 0-9, including Unicode).
Examples:
python
print("Python123".isalnum()) # True (ASCII letters & digits)
print("Pythรถn123".isalnum()) # True (Unicode 'รถ' is alphabetic)
print("เฅงเฅจเฅฉabc".isalnum()) # True (Devanagari digits + ASCII letters)
print("Python_123".isalnum()) # False (underscore not allowed)
Key Differences
| Method | ASCII (0-9) | Unicode Digits (ยฒ, ยพ, โ ง) | Letters (a-z, A-Z) | Others (_, ., etc.) |
|---|---|---|---|---|
isdigit() | โ Yes | โ Yes (superscripts, etc.) | โ No | โ No |
isnumeric() | โ Yes | โ Yes (fractions, Roman numerals) | โ No | โ No |
isdecimal() | โ Yes | โ Only decimal digits (Devanagari, etc.) | โ No | โ No |
isalnum() | โ Yes | โ Yes (if digits) | โ Yes | โ No |
When to Use Which?
isdigit()ย โ Check if a string is a valid integer (including superscripts).isnumeric()ย โ Check if a string represents any numeric value (including fractions).isdecimal()ย โ Strictly check for decimal digits (useful for number parsing).isalnum()ย โ Validate usernames, passwords (letters + digits only).
เคนเคฟเคเคฆเฅ เค เคเค (1 เคธเฅ 10) เคเฅ เคฏเฅเคจเคฟเคเฅเคก เคเฅเคก เคชเฅเคเคเคเฅเคธ
เคนเคฟเคเคฆเฅ (เคฆเฅเคตเคจเคพเคเคฐเฅ) เค เคเคเฅเค เคเฅ เคฏเฅเคจเคฟเคเฅเคก เคชเฅเคฐเคคเคฟเคจเคฟเคงเคฟเคคเฅเคต เคเฅ เคชเฅเคฐเฅ เคธเฅเคเฅ เคฏเคนเคพเค เคฆเฅ เคเค เคนเฅ:
| เค เคเค | เคนเคฟเคเคฆเฅ เค เคเค | เคฏเฅเคจเคฟเคเฅเคก เคเฅเคก | เคฏเฅเคจเคฟเคเฅเคก เคจเคพเคฎ |
|---|---|---|---|
| 0 | เฅฆ | U+0966 | DEVANAGARI DIGIT ZERO |
| 1 | เฅง | U+0967 | DEVANAGARI DIGIT ONE |
| 2 | เฅจ | U+0968 | DEVANAGARI DIGIT TWO |
| 3 | เฅฉ | U+0969 | DEVANAGARI DIGIT THREE |
| 4 | เฅช | U+096A | DEVANAGARI DIGIT FOUR |
| 5 | เฅซ | U+096B | DEVANAGARI DIGIT FIVE |
| 6 | เฅฌ | U+096C | DEVANAGARI DIGIT SIX |
| 7 | เฅญ | U+096D | DEVANAGARI DIGIT SEVEN |
| 8 | เฅฎ | U+096E | DEVANAGARI DIGIT EIGHT |
| 9 | เฅฏ | U+096F | DEVANAGARI DIGIT NINE |
| 10 | เฅงเฅฆ | U+0967 U+0966 | ONE + ZERO |
เคชเคพเคฏเคฅเคจ เคฎเฅเค เคเคชเคฏเฅเค เคเฅ เคเคฆเคพเคนเคฐเคฃ
python
# เคนเคฟเคเคฆเฅ เค
เคเคเฅเค เคเฅ เคชเฅเคฐเคฟเคเค เคเคฐเคจเคพ
hindi_numbers = ["เฅฆ", "เฅง", "เฅจ", "เฅฉ", "เฅช", "เฅซ", "เฅฌ", "เฅญ", "เฅฎ", "เฅฏ"]
for num in hindi_numbers:
print(num, end=' ')
# เคเคเคเคชเฅเค: เฅฆ เฅง เฅจ เฅฉ เฅช เฅซ เฅฌ เฅญ เฅฎ เฅฏ
# เคฏเฅเคจเคฟเคเฅเคก เคเฅเคก เคเคพ เคเคชเคฏเฅเค เคเคฐเคเฅ
print("\nเฅงเฅฆ") # U+0967 (เฅง) + U+0966 (เฅฆ)
# isdigit() เคเคฐ isnumeric() เคเฅ เคธเคพเคฅ เคเคพเคเค
num = "เฅงเฅจเฅฉ"
print(num.isdigit()) # True
print(num.isnumeric()) # True
print(num.isdecimal()) # True
เคฎเคนเคคเฅเคตเคชเฅเคฐเฅเคฃ เคคเคฅเฅเคฏ
- เคฏเฅ เคธเคญเฅ เค
เคเคย
isdigit(),ยisnumeric()ย เคเคฐยisdecimal()ย เคเฅ เคฒเคฟเคยTrueย เคฐเคฟเคเคฐเฅเคจ เคเคฐเคคเฅ เคนเฅเค - เคฏเฅเคจเคฟเคเฅเคก เคฐเฅเคเค:ย U+0966 เคธเฅ U+096Fย เคคเค
- 10 เคเฅ เคฆเคฐเฅเคถเคพเคจเฅ เคเฅ เคฒเคฟเค ‘เฅง’ เคเคฐ ‘เฅฆ’ เคเฅ เคธเคเคฏเฅเคเคฟเคค เคเคฐเฅเค (U+0967 + U+0966)
Telugu Numbers (0 to 10) with Unicode Codes
Here’s the complete list of Telugu numerals with their Unicode representations:
| Number | Telugu Numeral | Unicode Code | Unicode Name |
|---|---|---|---|
| 0 | เฑฆ | U+0C66 | TELUGU DIGIT ZERO |
| 1 | เฑง | U+0C67 | TELUGU DIGIT ONE |
| 2 | เฑจ | U+0C68 | TELUGU DIGIT TWO |
| 3 | เฑฉ | U+0C69 | TELUGU DIGIT THREE |
| 4 | เฑช | U+0C6A | TELUGU DIGIT FOUR |
| 5 | เฑซ | U+0C6B | TELUGU DIGIT FIVE |
| 6 | เฑฌ | U+0C6C | TELUGU DIGIT SIX |
| 7 | เฑญ | U+0C6D | TELUGU DIGIT SEVEN |
| 8 | เฑฎ | U+0C6E | TELUGU DIGIT EIGHT |
| 9 | เฑฏ | U+0C6F | TELUGU DIGIT NINE |
| 10 | เฑงเฑฆ | U+0C67 U+0C66 | ONE + ZERO |
Python Examples with Telugu Numbers
python
# Printing Telugu numbers 0-10
telugu_nums = ["เฑฆ", "เฑง", "เฑจ", "เฑฉ", "เฑช", "เฑซ", "เฑฌ", "เฑญ", "เฑฎ", "เฑฏ"]
for num in telugu_nums:
print(num, end=' ')
# Output: เฑฆ เฑง เฑจ เฑฉ เฑช เฑซ เฑฌ เฑญ เฑฎ เฑฏ
# Printing 10 in Telugu
print("\nเฑงเฑฆ") # U+0C67 (เฑง) + U+0C66 (เฑฆ)
# Validation checks
num = "เฑงเฑจเฑฉ"
print(num.isdigit()) # True
print(num.isnumeric()) # True
print(num.isdecimal()) # True
Key Features
- All Telugu digits returnย
Trueย forยisdigit(),ยisnumeric(), andยisdecimal() - Unicode range:ย U+0C66 to U+0C6F
- To represent 10, combine ‘เฑง’ (ONE) and ‘เฑฆ’ (ZERO)
Additional Information
- These digits are part of the Telugu script block in Unicode (U+0C00 to U+0C7F)
- They are used in the Telugu language, primarily spoken in the Indian states of Andhra Pradesh and Telangana
- The numerals follow the Hindu-Arabic numeral system positional notation