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

     

  • 相关阅读:
    应用一:Vue之开发环境搭建
    基于vue项目的js工具方法汇总
    JavaScript 格式化数字、金额、千分位、保留几位小数、舍入舍去… 及其浮点数计算精度问题(推荐的类库 Numeral.js 和 accounting.js)
    Redis源码分析(二十五)--- zmalloc内存分配实现
    Redis源码分析(二十五)--- zmalloc内存分配实现
    SpringBoot系列——WebMvcConfigurer介绍
    跨域问题与SpringBoot解决方案
    源码分析SpringBoot启动
    SpringBoot+SpringSecurity+jwt整合及初体验
    【mysql学习】InnoDB数据结构
  • 原文地址:https://www.cnblogs.com/xujianghua/p/5237546.html
Copyright © 2011-2022 走看看