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

Thomas 'PointedEars' Lahn PointedEars at web.de
Wed May 16 17:07:28 EDT 2012


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?

RTFM.

$ python3 -c 'print("42".isdecimal.__doc__ + "\n"); 
print("42".isdigit.__doc__)'
S.isdecimal() -> bool

Return True if there are only decimal characters in S,
False otherwise.

S.isdigit() -> bool

Return True if all characters in S are digits
and there is at least one character in S, False otherwise.

-- 
PointedEars

Please do not Cc: me. / Bitte keine Kopien per E-Mail.



More information about the Python-list mailing list