字符串常用操作之其他

.replace()

.join()

.format()

name='alex say :i have one tesla,my name is alex'
print(name.replace('alex','SB',1)) #字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串
tag=' '
print(tag.join(['egon','say','hello','world'])) #将序列中的元素以指定的字符连接生成一个新的字符串,可迭代对象必须都是字符串
# format的三种玩法
res='{} {} {}'.format('egon',18,'male')
res='{1} {0} {1}'.format('egon',18,'male')
res='{name} {age} {sex}'.format(sex='male',name='egon',age=18)
print(res)
posted @ 2020-05-03 09:42  huangjunlong  阅读(76)  评论(0)    收藏  举报