Python String isdigit() Function

Python's built-in isdigit() function is used to process strings. This function will print out True if the string contains all digits otherwise it will print out False. The string only needs to contain 1 non-numeric character, it will also return False.

Here at LinuxAPT, we shall look into how to use the isdigit() function in Python.


More about isdigit() Function

The isdigit() function prints out True if the string contains all digits otherwise it will print out False.

The string only needs to contain 1 non-numeric character, it will also return False.

It's syntax is given below:

string.isdigit()

The Parameter Values provides now value.


Examples of using isdigit() Function

1. Take a look at the below function:

str = "82444"
x = str.isdigit()
print(x)

It's Output will give:

True


2. Another one is given below:

str = "46354f4"
x = str.isdigit()
print(x)

It's output will give:

False


3. You can consider the function below:

str1 = "46354f4"
print(str1.isdigit())
str2 = "\u0035" #unicode for 5
print(str2.isdigit())

It's output will give:

False
True


4. Lastly, the below function:

str = "00000"
print(str.isdigit())

The output will give:

True


[Need help in fixing Python function issues? We can help you. ]

This article covers how to use the isdigit() function in Python. In fact, the isdigit() method returns True if all characters in a string are digits or Unicode char of a digit. If not, it returns False.


Return Value from isdigit()

The isdigit() returns:

  • True if all characters in the string are digits.
  • False if at least one character is not a digit.

Related Posts