Scripting

Python isdigit() Function

Python isdigit() Function

Introduction

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.

Now we will show you about using the isdigit() function in Python.

Example

Example 1:

str = "82444"

x = str.isdigit()

print(x)

Output:

True

Example 2:

str = "46354f4"

x = str.isdigit()

print(x)

Output:

False

Definition

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.

The syntax

string.isdigit()

Parameter Values:

No value.

More examples

Example 1:

str1 = "46354f4"

print(str1.isdigit())

str2 = "\u0035" #unicode for 5

print(str2.isdigit())

Output:

False

True

Example 2:

str = "00000"

print(str.isdigit())

Output:

True

Conclusion

We just showed you to use the isdigit() function in Python.

Thank you for reading!

Similar Posts