|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 一个账号 于 2020-3-6 21:20 编辑
- num = "1" # Unicode
- num.isdigit() # True
- num.isdecimal() # True
- num.isnumeric() # True
- num = "1" # 全角
- num.isdigit() # True
- num.isdecimal() # True
- num.isnumeric() # True
- num = b"1" # byte
- num.isdigit() # True
- num.isdecimal() # AttributeError 'bytes' object has no attribute 'isdecimal'
- num.isnumeric() # AttributeError 'bytes' object has no attribute 'isnumeric'
- num = "Ⅵ" # 罗马数字
- num.isdigit() # False
- num.isdecimal() # False
- num.isnumeric() # True
- num = "四" # 汉字
- num.isdigit() # False
- num.isdecimal() # False
- num.isnumeric() # True
复制代码
========================================================================
isdigit()
True: Unicode 数字,byte 数字(单字节),全角数字(双字节)
False: 汉字数字,罗马数字
Error: 无
isdecimal()
True: Unicode 数字,全角数字(双字节)
False: 汉字数字,罗马数字
Error: byte 数字(单字节)
isnumeric()
True: Unicode 数字,全角数字(双字节),罗马数字,汉字数字
False: 无
Error: byte 数字(单字节)
isdigit() 和 isdecimal() 基本相同 |
|