python去除换行符和空格

python去除换行符和空格,第1张

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', ''))

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/922541.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存