python判断字符串,str函数isdigit、isdecimal、isnumeric的区别
s为字符串
s.isalnum() 所有字符都是数字或者字母
s.isalpha() 所有字符都是字母
s.isdigit() 所有字符都是数字
s.islower() 所有字符都是小写
s.isupper() 所有字符都是大写
s.istitle() 所有单词都是首字母大写,像标题
s.isspace() 所有字符都是空白字符、\t、\n、\r
判断是整数还是浮点数
a=123
b=123.123
>>>isinstance(a,int)
True
>>>isinstance(b,float)
True
>>>isinstance(b,int)
False
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的区别的更多相关文章
- Python3中isdigit(), isdecimal(), isnumeric()的区别和字符串的常用方法
# 全部小写 string.lower() # 全部大写 string.upper() # 是否全部小写 string.islower() # 是否全部大写 string.isupper() # 首字 ...
- Python判断字符串编码以及编码的转换
转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...
- python判断字符串
python判断字符串 s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小 ...
- python判断字符串是否是json格式方法分享
python判断字符串是否是json格式方法分享 在实际工作中,有时候需要对判断字符串是否为合法的json格式 解决方法使用json.loads,这样更加符合'Pythonic'写法 代码示例: ...
- js判断字符串str是否包含字符串substr
js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); ...
- python判断字符串是否为空的方法s.strip()=='' if not s.strip():
python 判断字符串是否为空用什么方法? 复制代码 s=' ' if s.strip()=='': print 's is null' 或者 if not s.strip(): p ...
- python 判断字符串中是否只有中文字符
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...
- python判断字符串中是否包含子字符串
python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1: print('存在') else: print('不存在' ...
- python中字符串(str)的常用处理方法
str='python String function' 生成字符串变量str='python String function' 字符串长度获取:len(str)例:print '%s length= ...
随机推荐
- 区间合并 --- Codeforces 558D : Gess Your Way Out ! II
D. Guess Your Way Out! II Problem's Link: http://codeforces.com/problemset/problem/558/D Mean: 一棵满二叉 ...
- Linq查询操作之Where筛选
筛选操作where能够处理逻辑运算符组成的逻辑表达式.比如逻辑“与”,逻辑“或”,并从数据源中筛选数据,它和where子句的功能非常相似.Enumerable类的Where()原型如下: public ...
- Linq之group子句
在Linq查询语句中,group子句主要作用是对查询的结果集进行分组.并返回元素类型为IGrouping<TKey,TElement>的对象序列. 下面我们在代码实例中创建一个GroupQ ...
- MVC应用程序中管理(更新)上传的文件
实现上传文件功能,有时上传也会操作出错,能让用户有改正有机会,开发上传文件能有更新的功能. 文件上传时,如果是存储于应用程序某一目录的话,在更新时需要了解一些流程,先是删除旧文件,更新数据表相关信息, ...
- Studio for Winforms FlexGrid:导出到 PDF 文件
本篇文章主要介绍如何导出 FlexGrid 到 PDF 格式文件.本文源于论坛用户,有多个用户提出如何把 FlexGrid 导出到 PDF 文件的需求.在这里共享给大家. 当前,ComponentOn ...
- OAuth2.0 基础概述
web:http://oauth.net/2/ rfc:http://tools.ietf.org/html/rfc6749 doc:http://oauth.net/documentation/ c ...
- 外表cms,内在wiki的系统anwiki
比较完整面向对象的语法格式, 外表cms,内在wiki的系统 http://enanocms.org/features 比较老,php4的语法
- [转]基于 Quercus 的手游项目终于上线了
原文:http://blog.andsky.com/quercus-php-ngame/ 经过半年的开发,我们第一款手游戏终于开发完毕,架构使用了 netty + Quercus 实现用 php 通过 ...
- ugui 获取Text的高度,动态改变高度
项目中需要根据聊天内容的多少.显示外边框的高度.因为Text的内容是不固定的.但宽度是固定的.高度根据文字多少自增 可以通过Text的属性preferredHeight 获取文本框的高度
- mybatis中#和$符号的区别
mybatis做为一个轻量级ORM框架在许多项目中使用,因其简单的入门受到了广大开发者的热爱.在近期项目中再做一个相关的开发,碰到了#.$符号这样的问题,之前没怎么注意过,通过学习之后,有了点感悟,分 ...