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

Ian Kelly ian.g.kelly at gmail.com
Wed May 16 13:02:22 EDT 2012


On Wed, May 16, 2012 at 10:24 AM, Ulrich Eckhardt <doomster at knuut.de> wrote:
> Marco wrote:
>>  >>> '123'.isdecimal(), '123'.isdigit()
>> (True, True)
>>  >>> print('\u0660123')
>> ٠123
>>  >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal()
>> (True, True)
>>  >>> print('\u216B')
>>>>  >>> '\u216B'.isdecimal(), '\u216B'.isdigit()
>> (False, False)
>> [chr(a) for a in range(0x20000) if chr(a).isdigit()]
>> Congratulations, you found a bug! Or maybe not, it all depends on whether
> Roman numbers are considered digits or not. I could imagine there being a
> difference.

They're not. The word "digit" specifically refers to the symbols used
by a positional numeral system, e.g. Arabic numerals. Roman numerals
are not a positional system. The word "decimal" in this case more
specifically means a digit character that is actually suitable for
using to compose a decimal number.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /