# find:顾头不顾尾,找不到则返回-1不会报错,找到了显示索引
x ="hello egon egon egon"
res=x.find("egon")print(res)# >>>6
res=x.find("egon123")print(res)# >>>-1(找不到)
res=x.find("egon",0,3)print(res)# >>>-1(找不到)
rfind:最后一个'egon'的第一个字母位置
res = x.rfind("egon")print(res)# >>>16
index:顾头不顾尾,找到了输出索引,找不到会报错!!!
res = x.index("egon123")print(res)# 找不到则报错
count:顾头不顾尾,如果不指定范围则查找所有,找不回会显示0!!!
res = x.count('egon')print(res)# >>>3
res = x.count('e',0,1)print(res)# >>>0
2、center,ljust,rjust,zfill
# center:变量值居中,指定任意字符填充满10个字符
x ="egon"
res = x.center(10,'*')print(res)# >>>***egon***# ljust:变量值在左侧,用任意字符从变量值最后一个字符开始填充满10个字符print(x.ljust(10,"*"))# >>>egon******# rjust:变量值在右侧,用任意字符从左侧开始填充加上变量值满10个字符print(x.rjust(10,"*"))# >>>******egon# zfill:用0填充满指定数的字符print(x.zfill(10))# >>>000000egon
3、expandtabs: 将tab符号’\t’符号转为空格
name='egon\thello'print(name)# >>> egon helloprint(name.expandtabs(1))# >>>egon hello
4、captalize,swapcase,title
captalize:首字母大写(只有第一个字母会大写)
print("hello world egon".capitalize())# >>>Hello world egon
swapcase:大小写翻转
print("aBcDeF".swapcase())# >>>AbCdEf
title:每个单词的首字母大写
print("hello world egon".title())# >>>Hello World Egon