标签:unicodedata isnumeric python isdecimal 处理 isdigit num 字符串 True
s为字符串
s.isalnum() 所有字符都是数字或者字母
s.isalpha() 所有字符都是字母
s.isdigit() 所有字符都是数字
s.islower() 所有字符都是小写
s.isupper() 所有字符都是大写
s.istitle() 所有单词都是首字母大写,像标题
s.isspace() 所有字符都是空白字符、\t、\n、\r
1 判断是整数还是浮点数 2 a=123 3 b=123.123 4 5 >>>isinstance(a,int) 6 True 7 >>>isinstance(b,float) 8 True 9 >>>isinstance(b,int) 10 False
1 python中str函数isdigit、isdecimal、isnumeric的区别 2 num = "1" #unicode 3 num.isdigit() # True 4 num.isdecimal() # True 5 num.isnumeric() # True 6 7 num = "1" # 全角 8 num.isdigit() # True 9 num.isdecimal() # True 10 num.isnumeric() # True 11 12 num = b"1" # byte 13 num.isdigit() # True 14 num.isdecimal() # AttributeError 'bytes' object has no attribute 'isdecimal' 15 num.isnumeric() # AttributeError 'bytes' object has no attribute 'isnumeric' 16 17 num = "IV" # 罗马数字 18 num.isdigit() # True 19 num.isdecimal() # False 20 num.isnumeric() # True 21 22 num = "四" # 汉字 23 num.isdigit() # False 24 num.isdecimal() # False 25 num.isnumeric() # True 26 27 =================== 28 isdigit() 29 True: Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字 30 False: 汉字数字 31 Error: 无 32 33 isdecimal() 34 True: Unicode数字,,全角数字(双字节) 35 False: 罗马数字,汉字数字 36 Error: byte数字(单字节) 37 38 isnumeric() 39 True: Unicode数字,全角数字(双字节),罗马数字,汉字数字 40 False: 无 41 Error: byte数字(单字节) 42 43 ================ 44 import unicodedata 45 46 unicodedata.digit("2") # 2 47 unicodedata.decimal("2") # 2 48 unicodedata.numeric("2") # 2.0 49 50 unicodedata.digit("2") # 2 51 unicodedata.decimal("2") # 2 52 unicodedata.numeric("2") # 2.0 53 54 unicodedata.digit(b"3") # TypeError: must be str, not bytes 55 unicodedata.decimal(b"3") # TypeError: must be str, not bytes 56 unicodedata.numeric(b"3") # TypeError: must be str, not bytes 57 58 unicodedata.digit("Ⅷ") # ValueError: not a digit 59 unicodedata.decimal("Ⅷ") # ValueError: not a decimal 60 unicodedata.numeric("Ⅷ") # 8.0 61 62 unicodedata.digit("四") # ValueError: not a digit 63 unicodedata.decimal("四") # ValueError: not a decimal 64 unicodedata.numeric("四") # 4.0View Code
标签:unicodedata,isnumeric,python,isdecimal,处理,isdigit,num,字符串,True 来源: https://www.cnblogs.com/laoyw/p/10344093.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。