这里写自定义目录标题
python字符串一次替换多个字符使用replace替换多处
遇到问题,如何替换爬取的时间数据是用中文字符保存的,如1997年6月6日,想要替换成1997-6-6,方法如下
def change_Time_Type(times):
new_times = []
for i in range(len(times)):
new_times.append(times[i].replace("年", "-").replace("月", "-").replace("日", ""))
print(new_times)
return new_times
清除段前段后空格或字符方法
str = "*****this is **string** example....wow!!!*****"
print (str.strip( '*' )) # 指定字符串 *
print (str.strip( )) #清除空格

文章介绍了如何在Python中使用replace函数一次性替换字符串中的多个字符,例如将中文日期格式‘年月日’转换为‘-’分隔的西历日期格式,并展示了清除字符串前后特定字符的方法。
4838

被折叠的 条评论
为什么被折叠?



