str1 = '2222222222222222asdasdadas22222222222'
# 去除首位字符串
print(str1.strip('2'))
str2 = ' asdasdadas '
# 去除首位字符串空格
print(str2.strip())
# replace() 替换中间字符串
#str.replace(old, new[, max])
# old – 将被替换的子字符串。
# new – 新字符串,用于替换old子字符串。
# max – 可选字符串, 替换不超过 max 次
print(str1.replace('a','C'))
# 去除首位字符串空格,中间空格,回车符,换行符
print(str.strip().replace(' ', '').replace('\n', '').replace('\r', ''))
python去除换行符和空格
最新推荐文章于 2023-05-26 05:42:23 发布