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

  1. num = "1" #unicode
    num.isdigit() # True
    num.isdecimal() # True
    num.isnumeric() # True
  2.  
  3. num = "1" # 全角
    num.isdigit() # True
    num.isdecimal() # True
    num.isnumeric() # True
  4.  
  5. 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'
  6.  
  7. num = "IV" # 罗马数字
    num.isdigit() # True
    num.isdecimal() # False
    num.isnumeric() # True
  8.  
  9. num = "四" # 汉字
    num.isdigit() # False
    num.isdecimal() # False
    num.isnumeric() # True
  10.  
  11. ===================
    isdigit()
    True: Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
    False: 汉字数字
    Error:
  12.  
  13. isdecimal()
    True: Unicode数字,,全角数字(双字节)
    False: 罗马数字,汉字数字
    Error: byte数字(单字节)
  14.  
  15. isnumeric()
    True: Unicode数字,全角数字(双字节),罗马数字,汉字数字
    False:
    Error: byte数字(单字节)
  16.  
  17. ================
    import unicodedata
  18.  
  19. unicodedata.digit("2") # 2
    unicodedata.decimal("2") # 2
    unicodedata.numeric("2") # 2.0
  20.  
  21. unicodedata.digit("2") # 2
    unicodedata.decimal("2") # 2
    unicodedata.numeric("2") # 2.0
  22.  
  23. 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
  24.  
  25. unicodedata.digit("Ⅷ") # ValueError: not a digit
    unicodedata.decimal("Ⅷ") # ValueError: not a decimal
    unicodedata.numeric("Ⅷ") # 8.0
  26.  
  27. unicodedata.digit("四") # ValueError: not a digit
    unicodedata.decimal("四") # ValueError: not a decimal
    unicodedata.numeric("四") # 4.0
  28.  
  29. #"〇","零","一","壱","二","弐","三","参","四","五","六","七","八","九","十","廿","卅","卌","百","千","万","万","亿"

python判断字符串,str函数isdigit、isdecimal、isnumeric的区别的更多相关文章

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

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

  2. Python判断字符串编码以及编码的转换

    转自:http://www.cnblogs.com/zhanhg/p/4392089.html Python判断字符串编码以及编码的转换 判断字符串编码: 使用 chardet 可以很方便的实现字符串 ...

  3. python判断字符串

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

  4. python判断字符串是否是json格式方法分享

    python判断字符串是否是json格式方法分享 在实际工作中,有时候需要对判断字符串是否为合法的json格式 解决方法使用json.loads,这样更加符合'Pythonic'写法 代码示例:   ...

  5. js判断字符串str是否包含字符串substr

    js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); ...

  6. python判断字符串是否为空的方法s.strip()=='' if not s.strip():

    python 判断字符串是否为空用什么方法? 复制代码 s=' ' if s.strip()=='':     print 's is null' 或者 if not s.strip():     p ...

  7. python 判断字符串中是否只有中文字符

    python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: ...

  8. python判断字符串中是否包含子字符串

    python判断字符串中是否包含子字符串 s = '1234问沃尔沃434' if s.find('沃尔沃') != -1:     print('存在') else:     print('不存在' ...

  9. python中字符串(str)的常用处理方法

    str='python String function' 生成字符串变量str='python String function' 字符串长度获取:len(str)例:print '%s length= ...

随机推荐

  1. ok6410 android driver(8)

    In the past, we know how to create and run a simple character device driver on pc, goldfish and ok64 ...

  2. JavaScript一些函数

    1.prompt()函数:有两个参数,一个是显示用户输入框上面的标签,另一个是输入框的初始值.用来接收用户输入的值,然后把它返回到代码中: 例如: <doctype html> <h ...

  3. Import 元素 (MSBuild)

    Import 元素 (MSBuild)             Visual Studio 2013                 .NET Framework 4 .NET Framework 3 ...

  4. 重构第10天:提取方法(Extract Method)

    理解:经常写的代码中,有一些计算逻辑比较复杂的方法,写下来一个很长很长的方法,我们可以把这个方法,根据功能,分解成单独的几个小方法.这样做不仅能够增加代码的可维护性,而且增加了易读性. 详解: 重构前 ...

  5. log4net日志记录

    这里是接着上一篇来优化的,上篇:ASP.NET MVC中错误日志信息记录 log4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方(文件,数据库,EventLog等),日志就是程序的黑 ...

  6. 清除浮动after

    .clearf{display: inline-block;} .clearf:after { content: "."; display: block; height:; cle ...

  7. 初识HTTP协议

    本篇文章从概念上初识HTTP协议,参考链接:http://www.runoob.com/http/http-tutorial.html 目录: 一.HTTP协议    HTTP 工作原理    HTT ...

  8. CSS3随内容自动伸缩的背景

    CSS3给我们带来一个非常实用的新属性:border-image,利用这个属性我们可以做出随着内容的增减自动伸缩的背景.废话不多说,看代码! HTML: <ol> <li>第一 ...

  9. Python学习一入门

    一.打印Hello和多行文本 print 打印 后跟单引号或者双引号 多行:3个单引号或者3个双引号 二.算术运算 2.1.加减乖法 默认1/2=0 如果需要小数运算,则需要一个运算术上加.或者.0 ...

  10. c语言 拼接字符串

    #include<stdio.h> #include<stdlib.h> void main() { ] = "ca"; ] = "lc" ...