翼度科技»论坛 编程开发 python 查看内容

Python中isdigit、isnumeric、isdecimal

5

主题

5

帖子

15

积分

新手上路

Rank: 1

积分
15
isdigit

字符串的isdigit方法用于判断字符串是否只包含数字,即0-9的字符
  1. print('1233'.isdigit()) # True
  2. print('12.33'.isdigit()) # False
复制代码
  
isnumeric

字符串的isnumeric方法可用于判断字符串是否是数字,数字包括Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
  1. print('23'.isnumeric()) # True
  2. print('五十五'.isnumeric()) # True
  3. print('Ⅵ'.isnumeric()) # True
  4. print("12345".isnumeric()) # True
复制代码
  
isdecimal

字符串的isdecimal方法检查字符串是否只包含十进制字符(Unicode数字,,全角数字(双字节))
一个字符串中包含除十进制数字之外的字符,如空字符串、空格、标点符号、小数点等字符都会认为为False.
  1. print('1233'.isdecimal()) # True
  2. #Python学习交流群:711312441
  3. print('12.33'.isdecimal()) # False
  4. print("0b1011".isdecimal()) # 二进制 False
  5. print("0o17".isdecimal()) # 八进制 False
  6. print("0x9F".isdecimal()) # 十六进制 False
  7. print("12345".isdecimal()) # 全角数字 True
  8. print("2/3".isdecimal()) # 分数 False
  9. print("①②③".isdecimal()) # 汉字数字 False
  10. print("ⅠⅡⅢ".isdecimal()) # 罗马数字 False
  11. print("2/3".isdecimal()) # 分数 False
复制代码
来源:https://www.cnblogs.com/python1111/p/17897138.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具