isdigit()
methodThe isdigit()
method is a built-in method in python for string handling. This method checks if the given string contains just digits such as 0123456789.
Note: Exponents, like ², are also considered to be digits.
string.isdigit()
The method isdigit()
takes no parameters.
The isdigit()
method returns true if all characters in the string are digits. Otherwise, it returns false.
The following code shows how to use the isdigit()
method in python:
# Python code to check whether the String# consist of digit onlyx = '458235001'print(x.isdigit())x = '\u0030243abir302'print(x.isdigit())# x = '²3447'# subscript is a digitx = '\u00B23447'print(x.isdigit())# x = '½'# A fraction is not digitx = '\u00BD'print(x.isdigit())
Note:
- “\u0030” is Unicode for 0
- “\u00B2” is Unicode for ²
- ‘\u00BD’ is Unicode for ½