zoukankan      html  css  js  c++  java
  • 字符串

    test = "alex"

    v = test.capitalize() #首字母大写

    print (v)

    v1 = test.casefold()#所有变有小写

    print(v1)

    v2 = test.lower()

    print(v2)

    v3 = test.center(20,"#)      

    print (v3)  

    结果:########alex########

    test = "alexalexr"

    v4 = test.count('e')

    print (v4)

    结果:2

    v4 = test.count('e',5)

    结果:1

    v5 = test.endswith('ex')

    v6 = test.startswith('ex')

    test = "i am {name},{age}"

    v = test.format(name='alex',age=19)

    test = "i am [0],[1]"

    v = test.format("alex",19")

    test = "uasf890"

    v = test.isalnum()  #只能字母+数字

    test = "12345678 9"

    v = test.expandtable(6)

    结果:12345678    9

    test = "as3df"

    v = test.isalpha()       #是否是字母

    False

    v = test.isdecimal()    是否数字

    v = test.isdigit()          是否数字

    v = test.isnumeric()     是否数字,支持中文

    test = "alex"

    v  = test.swapcase() 大小写转换

    test = "dsklfsdklf dklsfdf"

    v = test.isprintable()  #是否存在不可显示

    False ( , )

    test = " " 

    isspace() 是否全部是空格

    test = " Return is it ..."

    v1 = test.title() 转换为标题

    v2 = test.istitle() 是否为标题

    test = "nishifengerwoshisha"

    print(test)

    t = ' ' 

    v = t.join(test)

    print (v)

    n i s h ...

     v = "_".join(test)

    n_i_....

    test = "alex"

    v = test.ljust(20,"*")

    结果:alex*************...

    v = test.rjust(20,"*")

    *************20

    v = test.zfill(20)

    00000000000000000alex

    test = " alex "

    test.lstrip()  #去左空白

    test.rstrip() #去右

    test.strip()  #去左右

    test.lstrip("al")    #ex

    ------------------------

    必须掌握join,split,find,strip,upper,lower,replace

    --------------------------

    len,for,index,切片

  • 相关阅读:
    记录「十一月做题记录」
    题解「GMOJ6898 【2020.11.27提高组模拟】第二题」
    题解「CFGYM102331B Bitwise Xor」
    题解「Japan Alumni Group Summer Camp 2018 Day 2J AB Sort」
    题解「AGC048B Bracket Score」
    题解「中位数之中位数 median」
    记录「十月做题记录」
    测试「2020牛客NOIP赛前集训营-提高组(第五场)」
    测试「20201028测试总结」
    定时提醒助手
  • 原文地址:https://www.cnblogs.com/wrw202/p/9533417.html
Copyright © 2011-2022 走看看