Python String isdigit() Method

By Lenin Mishra

If you prefer to watch Youtube videos over reading blogs, check out our video on Python strings here.

Python String isdigit() method

The isdigit() method in Python, returns True if all characters are numerical digits. Exponents are also considered digits.

Syntax of isdigit() method
string.isdigit()

Returns True or False
Example

Code/Output

s = "1992"
print(s.isdigit())
>>> True

# Floating point number
s = "1992.10"
print(s.isdigit())
>>> False

# contains alphabets
s = "Pylenin1992"
print(s.isdigit())
>>> False

# contains alphabets and spaces
s = "Pylenin loves Python"
print(s.isdigit())
>>> False

# Empty string
s = ''
print(s.isdigit())
>>> False

# superscripts
s = '1992\u00B2'
print(s)
print(s.isdigit())
>>> 1992^2
>>> True

# fractions
s = '\u00BD'
print(s)
print(s.isdigit())
>>> 1/2
>>> False

As you can see, fractions don’t qualify as digits.

Check out other commonly used Python string methods.

  1. How to create a string in Python?
  2. How to access characters in a Python string?
  3. How to replace characters in a string in Python?
  4. How to concatenate strings in Python?
  5. How to iterate through a string in Python?
  6. Check if a Substring is Present in a Given String in Python
  7. Escape sequences in Python String
  8. Python String Formatting - The Definitive Guide