Difference between str.isdigit() and str.isdecimal() in Python 3

Ian Kelly ian.g.kelly at gmail.com
Wed May 16 12:08:58 EDT 2012


On Wed, May 16, 2012 at 9:48 AM, Marco <marco_u at nsgmail.com> wrote:
> Hi all, because
>
> "There should be one-- and preferably only one --obvious way to do it",
>
> there should be a difference between the two methods in the subject, but I
> can't find it:
>
>>>> '123'.isdecimal(), '123'.isdigit()
> (True, True)
>>>> print('\u0660123')
> ٠123
>>>> '\u0660123'.isdigit(), '\u0660123'.isdecimal()
> (True, True)
>>>> print('\u216B')
>>>>> '\u216B'.isdecimal(), '\u216B'.isdigit()
> (False, False)
>
> Can anyone give me some help?

Here's one example:

>>> '\u00B2'.isdecimal()
False
>>> '\u00B2'.isdigit()
True
>>> '\u00B2'
'²'

The distinction is explained in the docs at:
http://docs.python.org/py3k/library/stdtypes.html#str.isdigit

Cheers,
Ian



More information about the Python-list mailing list