字符串的查询方法

字符串的查询方法有:count(),find(),isdigit(),isalpha(),startswith(),endswith(),

islower(),isupper()

1.count():返回字符串某个元素的数量

      a='abcbdedfa'

      a.count('a')          return:2


2.find():返回元素的索引

    a='hello word'

    a.find('w')              return:6

    a.find('z')              return:-1

    a.find('l')                return:2

注意:1.在字符串没有查到元素返回结果为-1

           2.在字符串里面查询的元素有多个时,只返回第一个元素所在的索引位置


3.isdigit():判断字符串是否全是数字

        a=1215615

        b='hello word'

        a.isdigit()        return:true

        b.isdigit()        return:false


4.isalpha():判断是否全是字母

      a=1215615

      b='hello word'

       a.isalpha()        return:false

       b.isalpha()        return:true


5.startswith():是否以什么开头

    a='asdasda'

    a.startswith('ccc')     return:false

    b.startswith('asd')     return:true


6.endswith():是否以什么结尾

a='asdasda'

    a.endswith('ccc')     return:false

    b.endswith('da')     return:true


7.islower():判断字母是否全是小写

   a='Hewdawd'

   b='sadafasf'

    a.islower()         return:false

    b.islower()         return:true

8.isupper():判断字母是否全部为大写

你可能感兴趣的:(字符串的查询方法)