字符串

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\t9"

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\t\ndklsfdf"

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

False (\t,\n)

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,切片

 

posted on 2018-08-25 11:46  *-帝释天-*  阅读(90)  评论(0编辑  收藏  举报