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

Marco marco_u at nsgmail.com
Wed May 16 14:45:49 EDT 2012


On 05/16/2012 06:24 PM, Ulrich Eckhardt 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()]

Thanks to your list comprehension I found they are not equal:

 >>> set([chr(a) for a in range(0x10FFFF) if chr(a).isdigit()]) - \
... set([chr(a) for a in range(0x10FFFF) if chr(a).isdecimal()])

Marco



More information about the Python-list mailing list