python logo

isdigit python


Python hosting: Host, run, and code Python in the cloud!

The isdigit() method in Python is utilized to determine if a string consists entirely of numerical digits. If the entire string is made up of digits and is not empty, the method will return True, otherwise, it will return False. It’s a handy tool for validating user input or processing strings in various scenarios.

Syntax of isdigit()

To check if a string contains only digits using the isdigit() function in Python, use the following format:

str.isdigit()

It’s important to note that this method doesn’t take any parameters.

Example of isdigit()

Below are some illustrative examples to demonstrate the use of the isdigit() method:

str_example1 = u"string digit 1234"
print( str_example1.isdigit() )

str_example2 = u"12345"
print( str_example2.isdigit() )

Result of the above code:

False
True

For further reading on string methods in Python, you can navigate through the following:

Previous: isdecimal()Next: capitalize()





Leave a Reply: