Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
string functions

How to use isdecimal() function in Python

Dinesh

isdecimal() is a string function in python that is generally used to find whether or not all the characters given in a string are decimals.

  • If all the given characters in the string are decimals, the output will be displayed as “True.”

  • If all the characters in the given string are not decimals, the output will be displayed as “False.”

Example

  • In the first program, “Dinesh” is used as a string as there is no decimal character in the string output that will be displayed as False.

  • In the second one, “Dinesh2003.” is used as a string where only 2003 are decimals. However, none of characters in the string are decimals, so the output will be False.

  • In the third one, though the given string has decimals in it, the other characters are @,#, and $, so the output is False.

  • Finally, in the fourth code, the given string is 567911. Since all the given characters are decimals, the expected output is True.

k = "Dinesh"
print(k.isdecimal())

p= "Dinesh2003"
print(p.isdecimal())

s="123@#$"
print(s.isdecimal())

t="567911"
print(t.isdecimal())

RELATED TAGS

python
string functions
RELATED COURSES

View all Courses

Keep Exploring