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

前端 未结 5 1375
不知归路
不知归路 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:44

    a negative number a = "-10" would be false for all of these three

    a.isdecimal(), a.isdigit(), a.isnumeric()
    

    are False, False, False isdecimal() will have only 0 to 9 in any language, but with out negative signs isdigit() will have only 0 to 9 in any language, also in the "to the power of" positions. (decimal numbers in power, ex: 2 to the power of 5). isnumeric() is even broader spectrum.. it will also include more than 0 to 9 in any position, but it will also have Tens, hundred, thousands in any language, ex. roman 10 is X, its a valid isnumeric(). But all the three are false for: Negative numbers, ex: -10 and floating point numbers, ex: 10.1

提交回复
热议问题