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

Terry Reedy tjreedy at udel.edu
Thu May 17 09:32:24 EDT 2012


On 5/17/2012 4:23 AM, Devin Jeanpierre wrote:

> str.isdecimal = isdecimal(...)
>      S.isdecimal() ->  bool
>
>      Return True if there are only decimal characters in S,
>      False otherwise.
>
> Help on method_descriptor in str:
>
> str.isdigit = isdigit(...)
>      S.isdigit() ->  bool
>
>      Return True if all characters in S are digits
>      and there is at least one character in S, False otherwise.

> By the way, is it worth filing a bug report on the wording of
> str.isdecimal()? It seems to imply that ''.isdecimal() should be true.
> (It isn't.) Especially when compared like that to isdigit, which makes
> a point of noting this particular edge case.

I think both should read (choosing either decimals or digits)

Return True if S has at least one character and all are decimals/digits, 
False otherwise.

Feel free to submit an issue.

-- 
Terry Jan Reedy




More information about the Python-list mailing list