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 = "IV" # 罗马数字
num.isdigit() # True
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数字(单字节) ================
import unicodedata unicodedata.digit("2") # 2
unicodedata.decimal("2") # 2
unicodedata.numeric("2") # 2.0 unicodedata.digit("2") # 2
unicodedata.decimal("2") # 2
unicodedata.numeric("2") # 2.0 unicodedata.digit(b"3") # TypeError: must be str, not bytes
unicodedata.decimal(b"3") # TypeError: must be str, not bytes
unicodedata.numeric(b"3") # TypeError: must be str, not bytes unicodedata.digit("Ⅷ") # ValueError: not a digit
unicodedata.decimal("Ⅷ") # ValueError: not a decimal
unicodedata.numeric("Ⅷ") # 8.0 unicodedata.digit("四") # ValueError: not a digit
unicodedata.decimal("四") # ValueError: not a decimal
unicodedata.numeric("四") # 4.0 #"〇","零","一","壱","二","弐","三","参","四","五","六","七","八","九","十","廿","卅","卌","百","千","万","万","亿"

python中str函数isdigit、isdecimal、isnumeric的区别的更多相关文章

  1. Python3中isdigit(), isdecimal(), isnumeric()的区别和字符串的常用方法

    # 全部小写 string.lower() # 全部大写 string.upper() # 是否全部小写 string.islower() # 是否全部大写 string.isupper() # 首字 ...

  2. Python中function(函数)和methon(方法)的区别

    在Python中,对这两个东西有明确的规定: 函数function —— A series of statements which returns some value to a caller. It ...

  3. python判断字符串,str函数isdigit、isdecimal、isnumeric的区别

    s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小写s.isupper() ...

  4. Python中str()与repr()函数的区别——repr() 的输出追求明确性,除了对象内容,还需要展示出对象的数据类型信息,适合开发和调试阶段使用

    Python中str()与repr()函数的区别 from:https://www.jianshu.com/p/2a41315ca47e 在 Python 中要将某一类型的变量或者常量转换为字符串对象 ...

  5. Python中split()函数的用法及实际使用示例

    Python中split()函数,通常用于将字符串切片并转换为列表. 一.函数说明: split():语法:str.split(str="",num=string.count(st ...

  6. Python中利用函数装饰器实现备忘功能

    Python中利用函数装饰器实现备忘功能 这篇文章主要介绍了Python中利用函数装饰器实现备忘功能,同时还降到了利用装饰器来检查函数的递归.确保参数传递的正确,需要的朋友可以参考下   " ...

  7. Python 中的函数

    学了 Python 中的数据类型,语句,接下来就来说一下 Python 中的函数,函数是结构化编程的核心.我们使用函数可以增加程序的可读性.自定义函数时使用关键字def 函数由多条语句组成.在定义函数 ...

  8. 【313】python 中 print 函数用法总结

    参考:python 中 print 函数用法总结 参考:Python print() 函数(菜鸟教程) 参考:Python 3 print 函数用法总结 目录: 字符串和数值类型 变量 格式化输出 p ...

  9. python中filter函数

    python中filter()函数   filter()函数是 Python 内置的另一个有用的高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断 ...

随机推荐

  1. zabbix-3.4.14源码安装

    此次介绍一下,zabbix的源码安装,因为zabbix的依赖很多,所以源码安装有很多依赖需要安装 首先,下载zabbix源码包 wget https://nchc.dl.sourceforge.net ...

  2. Axure 交互样式和选项组的设置

    1.点击元件,点击属性,点击选中,点击图片,选择相应的图片,选中功能是当点击这个元件的时候,元件的变成相应的图片,然后再设置鼠标单击时的动作是选中,就可以实现选中某个元件的时候,元件会变成其他的图片. ...

  3. Spring @RequestParam、@RequestBody和@ModelAttribute区别

    一.@RequestParamGET和POST请求传的参数会自动转换赋值到@RequestParam 所注解的变量上1. @RequestParam(org.springframework.web.b ...

  4. HTML辅助方法

    顾名思义,HTML辅助方法(HTML Helper)就是用来辅助产生HTML之用,在开发View的时候一定会面对许多HTML标签,处理这些HTML的工作非常繁琐,为了降低View的复杂度,可以使用HT ...

  5. 微信小程序 密码键盘 - 密码页面组件 (原生小程序代码)

    1.WXML页面 <view> <!--<section class="mask" catchtap="canclePwd" wx:if ...

  6. VS Code 安装sass插件

    准备工作 在VS Code上新建一个项目,例:SASS  ,文件夹内包括css 和 sass 和 html  文件夹   在sass文件下新新建sass.scss 1.在拓展商店里搜索“easy sa ...

  7. Android查看appPackage和Activity的多种方法

    方法一 有源码的情况直接打开AndroidManifest.xml文件,文件会有package信息 android.intent.action.MAIN决定应用程序最先启动的Activity andr ...

  8. 【百度地图API】如何获取行政区域的边界?(转载)

    转自:http://www.cnblogs.com/milkmap/archive/2012/04/11/2442430.html 摘要:以前教过大家如何自行获取行政区域,或者自定义获取一个区域的边界 ...

  9. HTML table导出到Excel中的解决办法

    第一部分:html+js 1.需要使用的表格数据(先不考虑动态生成的table) <table class="table tableStyles" id="tabl ...

  10. 2015-10-05 js3

    Javascript 实例2九九乘法表 var s = ""; s += "<table>"; for (var i = 1; i < 10; ...