• 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

     

  • 相关阅读:
    前端战五渣学前端——跨域
    CSS3学习笔记
    Vue工程化入口文件main.js中Vue.config.productionTip = false含义
    CSS选择器有哪几种?举例轻松理解CSS选择器
    研究生综合英语 作文 作业
    tomcat部署项目的方法
    【Winfrom-无边框窗体】Winform如何拖动无边框窗体?
    C#调用默认浏览器打开网页的几种方法
    CefSharp在高DPI的屏幕上出现黑边(winform)
    c# 关于mongo bson转json的问题
  • 原文地址:https://www.cnblogs.com/xujianghua/p/5237546.html
Copyright © 2020-2023  润新知