• python_str 字符串的所有方法


    # _Author:huang
    # date: 2017/11/28

    # 字符串

    '''print("hello" * 3)
    print("hello world"[2:])

    print("llo" in "hello world")

    print(123 in [1232,123,345])

    print("Huang is a good teacher")
    print("%s is a good teacher" % "Huang")


    a = "123"
    b = "456"
    c = a+b
    print(c)

    d = ''.join([a, b]) # 拼接
    print(d)'''

    # str内置方法
    '''st = 'hello kitty {name} is {age}'
    st1 = 'he llo kitty'
    print(st.count('t')) # 统计元素个数
    print(st.capitalize()) # 首字母大写
    print(st.center(50, '-')) # 一共打印50个字符,并且字符串放中间
    print(st.endswith('it')) # 判定以某个字符串结尾
    print(st.startswith("h")) # 判定以某个字符串开头
    print(st.startswith("hel")) # 判定以某个字符串开头
    print(st1.expandtabs(tabsize=10)) #间隔10个字符
    print(st.find('t')) # 查找到第一个元素,并将第一个索引值返回
    print(st.format(name='huang',age = 30)) # 赋值,可以自动选定{}
    print(st.format_map({'name':'huang', 'age':20}))

    print(st.index('e'))
    print(st.isalnum()) #判定字符串是否是数字
    print('56566'.isalnum()) #判定字符串是否是数字
    print('dewf'.isalpha()) #判定字符串是否是字母

    print('323'.isdigit()) #判定字符串是否是整数数字
    print('2134'.isdigit())
    print('34abb'.isidentifier())#判定字符串是否是以非法开头
    print('Abc'.islower())
    print('ctAD'.isupper())
    print(' uu'.isspace())
    print('My name'.istitle()) #每个单词的手写字母大写
    print('My Title'.lower()) #大写变小写
    print('Mhfrue'.upper()) #小写变大写
    print('fhieHIOhgdwi'.swapcase()) #大小写互换
    print('My teig'.ljust(50,'*')) # 字符在左侧
    print('ciwbre'.rjust(23,'*')) # 字符在右边
    print("cbniv ")
    print('My title '.strip()) # 去掉换行符
    print('oh')

    print(' vnd '.replace('v', 'a')) #替换
    print("name".replace('name','life'))
    print('name name name'.replace('name', 'life',2))
    print('lame name'.rfind('a'))
    print('My title title'.split(' ')) # 字符串变为列表
    print('My title title'.split('i')) # 字符串变为列表
    print('my title title'.rsplit('i', 1)) #只分隔一次,从右往左
    print("my name".title()) #按照标题修改字符串
    '''


    # 重要的字符串方法
    '''print(st.count('l'))
    st.startswith('nfi')
    st.find('fre')
    st.center(30,'%')
    st.format()
    st.lower()
    st.upper()
    st.strip()
    st.replace()
    st.split()
    '''

  • 相关阅读:
    CMMI全称是Capability Maturity Model Integration,即能力成熟度模型集成
    【beta】Scrum站立会议第5次....11.7
    【beta】Scrum站立会议第3次....11.6
    补交进度条
    【beta】Scrum站立会议第1次....11.3
    【week7】psp
    【week6】psp
    【week6】约跑App视频链接
    【week6】团队贡献分
    【week6】用户数
  • 原文地址:https://www.cnblogs.com/1510152012huang/p/7910920.html
Copyright © 2020-2023  润新知