The isdigit method
The isdigit
method checks that a string consists only of digits. Nothing is passed to the method parameters. The method returns the Boolean values True
or False
.
Syntax
string.isdigit()
Example
Let's assume that the line consists only of numbers:
txt = '12345'
print(txt.isdigit())
Result of code execution:
True
Example
Now let's say there are other symbols in the line:
txt = '12345ab'
print(txt.isdigit())
Result of code execution:
False