zoukankan      html  css  js  c++  java
  • Python判断字符串是否为字母或者数字

    严格解析:有除了数字或者字母外的符号(空格,分号,etc.)都会False
    isalnum()必须是数字和字母的混合
    isalpha()不区分大小写
    复制代码
    str_1 = "123"
    str_2 = "Abc"
    str_3 = "123Abc"
    
    #用isdigit函数判断是否数字
    print(str_1.isdigit())
    Ture
    print(str_2.isdigit())
    False
    print(str_3.isdigit())
    False
    
    #用isalpha判断是否字母
    print(str_1.isalpha())    
    False
    print(str_2.isalpha())
    Ture    
    print(str_3.isalpha())    
    False
    
    #isalnum判断是否数字和字母的组合
    print(str_1.isalnum())    
    Ture
    print(str_2.isalnum())
    Ture
    print(str_1.isalnum())    
    Ture
    注意:如果字符串中含有除了字母或者数字之外的字符,比如空格,也会返回False

    ================

    python3判断字符串是字母/数字/大小写的系统函数:

    函数    含义
    字符串.isalnum()    所有字符都是数字或者字母,为真返回 Ture,否则返回 False。
    字符串.isalpha()     所有字符都是字母,为真返回 Ture,否则返回 False。
    字符串.isdigit()     所有字符都是数字,为真返回 Ture,否则返回 False。
    字符串.islower()    所有字符都是小写,为真返回 Ture,否则返回 False。
    字符串.isupper()    所有字符都是大写,为真返回 Ture,否则返回 False。
    字符串.istitle()    所有单词都是首字母大写,为真返回 Ture,否则返回 False。
    字符串.isspace()    所有字符都是空白字符,为真返回 Ture,否则返回 False。
    ---------------------  
    作者:第一行Python代码  
    来源:CSDN  
    原文:https://blog.csdn.net/godot06/article/details/80966646  
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    openwrt 相关文章
    负载均衡相关文章
    Today's Progress
    Rodrigues formula is beautiful, but uneven to sine and cosine. (zz Berkeley's Page)
    Camera Calibration in detail
    Fundamental Matrix in Epipolar
    Camera Calibration's fx and fy do Cares in SLAM
    FilterEngine::apply
    FilterEngine 类解析——OpenCV图像滤波核心引擎(zz)
    gaussBlur
  • 原文地址:https://www.cnblogs.com/fengff/p/10369193.html
Copyright © 2011-2022 走看看