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

Marco marco_u at nsgmail.com
Thu May 17 03:58:48 EDT 2012


On 05/17/2012 02:15 AM, Steven D'Aprano wrote:

> the Fine Manual has more detail, although I admit it isn't *entirely*
> clear what it is talking about if you're not a Unicode expert:
>
>
> http://docs.python.org/py3k/library/stdtypes.html#str.isdecimal

You are right, that is clear, thanks :)

> Examples:
>
> py>  c = '\u2155'
> py>  print(c)
>> py>  c.isdecimal(), c.isdigit(), c.isnumeric()
> (False, False, True)
> py>  import unicodedata
> py>  unicodedata.numeric(c)
> 0.2
>
> py>  c = '\u00B2'
> py>  print(c)
> ²
> py>  c.isdecimal(), c.isdigit(), c.isnumeric()
> (False, True, True)
> py>  unicodedata.numeric(c)
> 2.0

Perfect explanation, thanks again, Marco





More information about the Python-list mailing list