python字符串刪除第n個(gè)字符 python怎么替換很多特定字符串為其他的字符串?
python怎么替換很多特定字符串為其他的字符串?用鏈?zhǔn)教鎿Q,示例如下:str1 = "abcdef"str2 = str1.replace("a","1").replace("b","2")prin
python怎么替換很多特定字符串為其他的字符串?
用鏈?zhǔn)教鎿Q,示例如下:
str1 = "abcdef"str2 = str1.replace("a","1").replace("b","2")print(str2) #12cdef
2.用正則替換,示例如下:
import restr3 = "abcdef"str4= re.compile("(a|b)").sub("1",str1)print(str4)#11cdef
1 & 2結(jié)合應(yīng)該能解決問題