Python isdigit() Method
Description
Python isdigit() method checks whether the string consists only of digits. It only works for 0 and positive numbers.
Syntax
isdigit() method syntax:
str.isdigit()
Parameters
- None.
Return Value
Returns True if the string contains only digits, otherwise returns False.
Example
The following example demonstrates the isdigit() method:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
str = "123456" # The string contains only digits
print (str.isdigit())
str = "this is string example....wow!!!"
print (str.isdigit())
str = "0"
print (str.isdigit())
str = "-1"
print (str.isdigit())
The output of the above example is:
True False True False
Other Extensions
Python String