Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
edited by

I am a newbie in python, and I am currently studying about .isdecimal() and .isdigit() string functions. Could someone provide me with code examples of where these two methods differentiate?

>>> str.isdecimal('1')

True

>>> str.isdigit('1')

True

>>> str.isdecimal('1.0')

False

>>> str.isdigit('1.0')

False

>>> str.isdecimal('1/2')

False

>>> str.isdigit('1/2')

False

1 Answer

0 votes
by (108k points)
edited by

Please be informed that there are differences in them, but they're slightly rare. It essentially crops up with many Unicode characters, such as 2:

>>> c = '²'

>>> c.isdecimal()

False

>>> c.isdigit()

True

You can also do the unicode-distinction rabbit hole with the isnumeric method:

>>> c = '½' # ½

>>> c.isdecimal()

False

>>> c.isdigit()

False

>>> c.isnumeric()

True

If you are newbie and want to explore more about Python, then  learn python  from the below video tutorial:

Related questions

0 votes
1 answer
asked Jan 12, 2021 in Python by ashely (50.2k points)
0 votes
0 answers

Browse Categories

...