Python中isdigit、isnumeric、isdecimal,
Python中isdigit、isnumeric、isdecimal,
isdigit
字符串的isdigit方法用于判断字符串是否只包含数字,即0-9的字符
print('1233'.isdigit()) # True
print('12.33'.isdigit()) # False
isnumeric
字符串的isnumeric方法可用于判断字符串是否是数字,数字包括Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
print('23'.isnumeric()) # True
print('五十五'.isnumeric()) # True
print('Ⅵ'.isnumeric()) # True
print("12345".isnumeric()) # True
isdecimal
字符串的isdecimal方法检查字符串是否只包含十进制字符(Unicode数字,,全角数字(双字节))
一个字符串中包含除十进制数字之外的字符,如空字符串、空格、标点符号、小数点等字符都会认为为False.
print('1233'.isdecimal()) # True
#Python学习交流群:711312441
print('12.33'.isdecimal()) # False
print("0b1011".isdecimal()) # 二进制 False
print("0o17".isdecimal()) # 八进制 False
print("0x9F".isdecimal()) # 十六进制 False
print("12345".isdecimal()) # 全角数字 True
print("2/3".isdecimal()) # 分数 False
print("①②③".isdecimal()) # 汉字数字 False
print("ⅠⅡⅢ".isdecimal()) # 罗马数字 False
print("2/3".isdecimal()) # 分数 False
相关内容
- 用python将csv转excel (.xls和.xlsx)的几种方式,.xlsx和.xls
- python中x[:] x[::]用法总结,
- 使用Python合并多个Excel文件,日常工作中,合并Ex
- python3使用pandas备份mysql数据表,今天记录下pytho
- Win10操作系统安装Python,3.2powersh
- python原生数据类型(上),')print('2
- Python 潮流周刊第 30 期(摘要),愿景:帮助所有读者
- Python中Parser的用法,程序定义它需要的参数
- python使用selenium操作浏览器的教程,今天我们就来简单
- python中函数参数引用之传值/传址和copy/deepcopy,他们的
评论关闭