zoukankan      html  css  js  c++  java
  • python之字符串详解2

    逻辑判断字符串类型,返回布尔值

    1. islower

    描述:判断所有字符是否为小写

    语法:

        def islower(self): # real signature unknown; restored from __doc__
            """
            S.islower() -> bool
            
            Return True if all cased characters in S are lowercase and there is
            at least one cased character in S, False otherwise.
            """
            return False

    样例:

    name='allen'
    result=name.islower()    #判断字符都为小写
    print(result)
    
    True    #显示结果
    View Code

    2. isupper

    描述:判断所有字符是否为大写

    语法:

        def isupper(self): # real signature unknown; restored from __doc__
            """
            S.isupper() -> bool
            
            Return True if all cased characters in S are uppercase and there is
            at least one cased character in S, False otherwise.
            """
            return False

    样例:

    name='allen'
    result=name.isupper()    #判断所有字符为大写
    print(result)
    
    False    #显示结果
    View Code

    3. istitle

    描述:判断是否为title类型,即第一个字符为大写,其他为小写

    语法:

        def istitle(self): # real signature unknown; restored from __doc__
            """
            S.istitle() -> bool
            
            Return True if S is a titlecased string and there is at least one
            character in S, i.e. upper- and titlecase characters may only
            follow uncased characters and lowercase characters only cased ones.
            Return False otherwise.
            """
            return False

    样例:

    name='Allen'
    result=name.istitle()    #判断是否为title类型的字符串
    print(result)
    
    True    #显示结果
    View Code

    4. isalpha

    描述:判断所有字符是否为字母

    语法:

      def isalnum(self): # real signature unknown; restored from __doc__
            """
            S.isalnum() -> bool
            
            Return True if all characters in S are alphanumeric
            and there is at least one character in S, False otherwise.
            """
            return False

    样例:

    name = 'allen'
    result=name.isalpha()    #判断所有字符为字母
    print(result)
    
    True    #显示结果
    isalpha

    5. isdigit

    描述:判断所有字符是否为数字

    语法:

        def isdigit(self): # real signature unknown; restored from __doc__
            """
            S.isdigit() -> bool
            
            Return True if all characters in S are digits
            and there is at least one character in S, False otherwise.
            """
            return False

    样例:

    name = '123'
    result=name.isdigit()    #判断所有字符为数字
    print(result)
    
    True    #显示结果
    
    name = '123abc'
    result=name.isdigit()    #判断所有字符为数字
    print(result)
    
    False   #显示结果
    isdigit

    6. isdecimal

    描述:判断所有字符是否是十进制数

    语法:

        def isdecimal(self): # real signature unknown; restored from __doc__
            """
            S.isdecimal() -> bool
            
            Return True if there are only decimal characters in S,
            False otherwise.
            """
            return False

    样例:

    name = '123'
    result=name.isdecimal()    #判断所有字符是否是十进制
    print(result)
    
    True    #显示结果
    
    
    name = '123abc'
    result=name.isdecimal()    #判断所有字符是否是十进制
    print(result)
    
    False    #显示结果
    decimal

     

  • 相关阅读:
    CentOS 7安装NXLog服务
    CentOS 7下Nginx日志的定时拆分
    IIS服务器配置NXLog进行syslog转发(并解决GMT+8小时时差问题)
    Linux服务器和Nginx配置syslog转发
    CentOS 7下安装Slowhttptest DDoS检测工具
    接口自动化:六.pytest写用例
    linux: CentOs 环境下搭建nginx负载均衡
    linux: CentOs 环境下搭建nginx
    环境搭建:linux下tomcat接口测试环境部署
    环境搭建:linux环境下安装mysql数库
  • 原文地址:https://www.cnblogs.com/xujianghua/p/5237546.html
Copyright © 2011-2022 走看看