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

jmfauth wxjmfauth at gmail.com
Wed May 16 15:41:45 EDT 2012


On 16 mai, 17:48, Marco <marc... 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?
> Regards, Marco

It seems to me that it is correct, and the reason lies in this:

>>> import unicodedata as ud
>>> ud.category('\u216b')
'Nl'
>>> ud.category('1')
'Nd'
>>>
>>> # Note
>>> ud.numeric('\u216b')
12.0

jmf




More information about the Python-list mailing list