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" |
Result of the above code:
False True
For further reading on string methods in Python, you can navigate through the following:
Posted in documentation
Leave a Reply: