Python string isdigit() method
Python String isdigit() Method
Description
The isdigit() method checks whether a string consists of only digits.
Syntax
The syntax of the isdigit() method is as follows:
var.isdigit()
Parameters
None
Return Value
This method returns True if all characters in the string are digits. It returns False if at least one character is not a digit (0-9).
Example
The following example demonstrates the use of the isdigit() method.
var = "500081"
var1 = var.isdigit()
print("Original string:", var)
print("Does it contain only digits?:", var1)
var = "TutorialsPoint"
var2 = var.isdigit()
print("Original string:", var)
print("Does it contain only digits?:", var2)
var = "123.34"
var3 = var.isdigit()
print("Original string:", var)
print("Does it contain only digits?:", var3)
When you run this program, it will produce the following output −
Original string: 500081
Does it contain only digits?: True
Original string: TutorialsPoint
Does it contain only digits? : False
Original string: 123.34
Contains only digits? : False