What's the difference between str.isdigit, isnumeric and isdecimal in python?

前端 未结 5 1369
不知归路
不知归路 2020-11-27 13:21

When I run these methods

s.isdigit()
s.isnumeric()
s.isdecimal()

I always got as output or all True, or all False for each value of s (whic

5条回答
  •  庸人自扰
    2020-11-27 13:48

    By definition, isdecimal()isdigit()isnumeric(). That is, if a string is decimal, then it'll also be digit and numeric.

    Therefore, given a string s and test it with those three methods, there'll only be 4 types of results.

    +-------------+-----------+-------------+----------------------------------+
    | isdecimal() | isdigit() | isnumeric() |          Example                 |
    +-------------+-----------+-------------+----------------------------------+
    |    True     |    True   |    True     | "038", "੦੩੮", "038"           |
    |  False      |    True   |    True     | "⁰³⁸", "

提交回复
热议问题