python 字符串替换
text = open('text.txt','r',encoding='utf-8').read()
old,new = ['(',')',',','.'],['(',')',',','。']
def replace(old,new):
data = ''
for i in text:
if i in old: #为什么这里要加个判断了,因为可以减少计算量,不用每个都遍历,符合条件才遍历。
for o,j in enumerate(old):
if i == j:
i = new[o]
data = '%s%s' % (data,i)
print(data)
replace(old,new)

浙公网安备 33010602011771号