replace 替换
语法:str.replace(oldvalue, newvalue[, count])
oldvalue:将被替换的子字符串
newvalue:用于替换oldvalue的子字符串
count:数值次数,指定要替换多少个oldvalue,如果次数没有输入的话,那么久默认全部替换成新的字符串
a="hello world " a="hello world world world world" a="hello world world world world"
print(a.replace("world","wo")) print(a.replace("world","wo")) print(a.replace("world","wo,2"))
hello wo hello wo wo wo wo hello wo wo world world
https://blog.csdn.net/Hudas/article/details/128205412?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169573976716800188544297%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=169573976716800188544297&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-128205412-null-null.142^v94^insert_down1&utm_term=replace%E5%87%BD%E6%95%B0&spm=1018.2226.3001.4187
join 连接
语法:'sep'.join(sep_object)
sep:分割符,可为“,、;”,分隔符里面为空的话,那么就是元素或者字符串所有的值都合在一起了。
sep_object:分割对象,可为字符串、以及储存字符串的元组、列表、字典。
a=("hello","world","world","world","world")
print(".".join(a))
hello.world.world.world.world
a=["hello","world","world","world","world"]
print(".".join(a))
hello.world.world.world.world
a=("hello","world","world","world","world")
print(" ".join(a))
helloworldworldworldworld
81.字符串的常用操作_替换与合并_哔哩哔哩_bilibili 9.26
https://blog.csdn.net/weixin_50853979/article/details/125119368?ops_request_misc=&request_id=&biz_id=102&utm_term=python%20join%E5%87%BD%E6%95%B0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-125119368.142^v94^insert_down1&spm=1018.2226.3001.4187