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

MRAB python at mrabarnett.plus.com
Wed May 16 12:11:05 EDT 2012


On 16/05/2012 16:48, Marco 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

Try this:
 >>> different = [chr(c) for c in range(0x10000) if chr(c).isdigit() != 
chr(c).isdecimal()]
 >>> print(different)
['²', '³', '¹', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱', '⁰', '⁴', 
'⁵', '⁶', '⁷', '⁸', '⁹', '₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', 
'₉', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑴', '⑵', '⑶', '⑷', 
'⑸', '⑹', '⑺', '⑻', '⑼', '⒈', '⒉', '⒊', '⒋', '⒌', '⒍', '⒎', '⒏', '⒐', 
'⓪', '⓵', '⓶', '⓷', '⓸', '⓹', '⓺', '⓻', '⓼', '⓽', '⓿', '❶', '❷', '❸', 
'❹', '❺', '❻', '❼', '❽', '❾', '➀', '➁', '➂', '➃', '➄', '➅', '➆', '➇', 
'➈', '➊', '➋', '➌', '➍', '➎', '➏', '➐', '➑', '➒']


More information about the Python-list mailing list

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