isdecimal(): Check for Decimal Characters

isdecimal()
Returns True if all chars are decimal ( 0 to 9) in a string, Otherwise False is returned.
my_str='12345'print(my_str.isdecimal())      # Output is True
my_str='234ab'print(my_str.isdecimal())      # Output is False
my_str='234.45'print(my_str.isdecimal())      # Output is False

Difference between isnumeric(), isdigit() and isdecimal()

Use google to search translate 1234 to chinese , then use the output like this.
my_str='一千二百三十四'print(my_str.isnumeric())  # Trueprint(my_str.isdigit())    # False print(my_str.isdecimal())  # False
One more example
my_str = '2²'print(my_str.isnumeric())  # Trueprint(my_str.isdigit())    # True print(my_str.isdecimal())  # False
my_str = '½'print(my_str.isnumeric())  # Trueprint(my_str.isdigit())    # False print(my_str.isdecimal())  # False
isdigit() will allow only digits 0-9

Example 1: Basic Usage of isdecimal()

text = "12345"
print(text.isdecimal())  # Output: True

Example 2: Using isdecimal() with Non-decimal Characters

text = "123.45"
print(text.isdecimal())  # Output: False

Example 3: Difference Between isdecimal() and isnumeric()

The `isnumeric()` function returns True for non-standard decimal characters, while `isdecimal()` does not.
text = "123\u00B2"  # ² is superscript 2
print(text.isdecimal())  # Output: False
print(text.isnumeric())  # Output: True

Applications of isdecimal()

  • Input Validation: Confirm that input consists only of basic decimal numbers.
  • Data Filtering: Separate purely numeric strings from mixed content.

All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer