🌐
W3Schools
w3schools.com › python › ref_string_isdigit.asp
Python String isdigit() Method
Remove List Duplicates Reverse ... Python Certificate Python Training ... The isdigit() method returns True if all the characters are digits, otherwise False....
🌐
Programiz
programiz.com › python-programming › methods › string › isdigit
Python String isdigit()
Become a certified Python programmer. Try Programiz PRO! ... The isdigit() method returns True if all characters in a string are digits.
Discussions

How To use isdigit in python
Hello, today i wanted to make a tkinter program and i made an entry about age the i only wanted the entry to get int numebrs for age but i did anything but it didnt work i asked someone for help and she said that i need to use isdigit but she didnt say how to use it. i just want to know how ... More on discuss.python.org
🌐 discuss.python.org
13
0
August 18, 2024
For single-char strings, Strings' .isdigit() method is about 7% slower than simply checking ```if string in "0123456789"```. Possible bug?
This susprised me because I assumed that the algorithm behind STRING.isdigit() is essentially a for loop that goes through each character of the string to check if it's a member of "0123456789". That is incorrect, isdigit() checks against the entire "Decimal Digit" Unicode category (Nd) which has hundreds of code points in it. So 7% slower is not bad. To be fair that's a common mistake, its behavior is really not what it looks like at first glance. More on reddit.com
🌐 r/Python
16
2
June 17, 2020
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.3 documentation
February 25, 2026 - Return True if all characters in the string are alphanumeric and there is at least one character, False otherwise. A character c is alphanumeric if one of the following returns True: c.isalpha(), c.isdecimal(), c.isdigit(), or c.isnumeric().
🌐
Codecademy
codecademy.com › docs › python › strings › .isdigit()
Python | Strings | .isdigit() | Codecademy
April 25, 2025 - The .isdigit() method under the string class checks if all the elements in the string are digits; applicable elements also include special cases like superscript digits (¹, ², ³, etc.).
🌐
Tutorialspoint
tutorialspoint.com › python › string_isdigit.htm
Python String isdigit() Method
The python string isdigit() method is used to check whether the string consists of digits. This method returns true if all the characters in the input string are digits and there is atleast one character.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.isdigit.html
pandas.Series.str.isdigit — pandas 3.0.2 documentation
The exact behavior of this method, i.e. which unicode characters are considered as digits, depends on the backend used for string operations, and there can be small differences. For example, Python considers the ³ superscript character as a digit, but not the ⅕ fraction character, while PyArrow considers both as digits. For simple (ascii) decimal numbers, the behaviour is consistent. ... >>> s3 = pd.Series(["23", "³", "⅕", ""]) >>> s3.str.isdigit() 0 True 1 True 2 True 3 False dtype: bool
🌐
Vultr Docs
docs.vultr.com › python › standard-library › str › isdigit
Python str isdigit() - Check Digits Only | Vultr Docs
December 26, 2024 - The isdigit() method in Python is a built-in function in the str (string) class that checks whether all characters in a string are digits.
🌐
Reuven Lerner
lerner.co.il › home › blog › python › python’s str.isdigit vs. str.isnumeric
Python's str.isdigit vs. str.isnumeric — Reuven Lerner
April 30, 2019 - But there’s another way to test this, one which I use with my into Python classes, before we’ve covered exceptions: Strings have a great method called “isdigit” that we can run, to tell us whether a string contains only digits (0-9), or if it contains something else.
Find elsewhere
🌐
Devcuriosity
devcuriosity.com › manual › details › python-isdigit-function
Python - isdigit() function with examples. Check string for digits.
string.isdigit() is a built-in method that can be called on string, byte, and bytearray objects. It checks if a given object contains only digits (numeric characters).
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-isdigit-method
Python String isdigit() Method - GeeksforGeeks
May 1, 2025 - The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns True if each character in the string is a numeric digit (0-9) and False otherwise.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › isdigit.html
isdigit — Python Reference (The Right Way) 0.1 documentation
isdigit · Edit on GitHub · Returns a Boolean stating whether the string contains only digits. str. isdigit() bool · #TODO · For 8-bit strings, this method is locale-dependent. Returns False if string is empty.
Top answer
1 of 1
22

str.isdigit doesn't claim to be related to parsability as an int. It's reporting a simple Unicode property, is it a decimal character or digit of some sort:

str.isdigit()

Return True if all characters in the string are digits and there is at least one character, False otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.

In short, str.isdigit is thoroughly useless for detecting valid numbers. The correct solution to checking if a given string is a legal integer is to call int on it, and catch the ValueError if it's not a legal integer. Anything else you do will be (badly) reinventing the same tests the actual parsing code in int() performs, so why not let it do the work in the first place?

Side-note: You're using the term "utf-8" incorrectly. UTF-8 is a specific way of encoding Unicode, and only applies to raw binary data. Python's str is an "idealized" Unicode text type; it has no encoding (under the hood, it's stored encoded as one of ASCII, latin-1, UCS-2, UCS-4, and possibly also UTF-8, but none of that is visible at the Python layer outside of indirect measurements like sys.getsizeof, which only hints at the underlying encoding by letting you see how much memory the string consumes). The characters you're talking about are simple Unicode characters above the ASCII range, they're not specifically UTF-8.

🌐
Medium
medium.com › @RedBeret › pythons-isdigit-and-beyond-making-data-validation-easy-b6703821680b
Python’s isdigit and Beyond: Making Data Validation Easy | by RedBeret (Steven) | Medium
January 5, 2024 - This project not only leverages ... tools. Role and Importance: The isdigit() method in Python is essential for ensuring that a string is composed only of digits....
🌐
Python Tutorial
pythontutorial.net › home › python string methods › python string isdigit()
Python String isdigit(): Determine If all Characters in a String are Digits
December 29, 2020 - In this tutorial, you'll learn how to use the Python string isdigit() method to determine if all characters in a string are digits.
🌐
AskPython
askpython.com › home › python string isdigit() function
Python String isdigit() Function - AskPython
August 6, 2022 - Python String isdigit() function checks for the Digit characters in a string and returns True if the string consists of only digit characters.
🌐
Javatpoint
javatpoint.com › python-string-isdigit-method
Python String | isdigit() method with Examples - Javatpoint
Python Function Programs · capitalize() casefold() center(width ,fillchar) count(string,begin,end) encode() endswith(suffix ,begin=0,end=len(string)) expandtabs(tabsize = 8) find(substring ,beginIndex, endIndex) format(value) index(subsring, beginIndex, endIndex) isalnum() isalpha() isdecimal() isdigit() isidentifier() islower() isnumeric() isprintable() isupper() isspace() istitle() isupper() join(seq) ljust(width[,fillchar]) lower() lstrip() partition() replace(old,new[,count]) rfind(str,beg=0,end=len(str)) rindex(str,beg=0,end=len(str)) rjust(width,[,fillchar]) rstrip() rsplit(sep=None, ma
🌐
Reddit
reddit.com › r/python › for single-char strings, strings' .isdigit() method is about 7% slower than simply checking ```if string in "0123456789"```. possible bug?
r/Python on Reddit: For single-char strings, Strings' .isdigit() method is about 7% slower than simply checking ```if string in "0123456789"```. Possible bug?
June 17, 2020 -

I was looking to optimize a program of mine that works on very, very large text files. I was fiddling around with various algorithms that perform a certain task on said data, one part of which is to convert characters to an integer;

which, of course, first has to check whether the character is an integer in the first place.

try/except was slow for my intents and purposes, so I went with the good old-fashioned if-elif-else and ran various time-measuring tests on some 2 GB of text.

My findings:

if c.isdigit(): is about 7% slower than if c in "0123456789"

This susprised me because I assumed that the algorithm behind STRING.isdigit() is essentially a for loop that goes through each character of the string to check if it's a member of "0123456789".

And since I'm trying out both time-tests on ONE-character strings only, my expectation was that the performance times would be equal.

Well... they're not, as pointed above.

Should this be considered a bug? Clearly, c.isdigit() isn't operating as efficiently as it should.

🌐
GeeksforGeeks
geeksforgeeks.org › python-string-isdigit-application
Python String isdigit() and its application - GeeksforGeeks
August 21, 2020 - The isdigit() method returns “True” if all characters in the string are digits, Otherwise, It returns “False”. This function is used to check if the argument contains digits such as: 0123456789 Syntax :