How to remove spaces and carriage returns from strings in python

Content takes this

str = ' 123 456 '
print(str.strip())
#去除左右两边的空格
print(str.lstrip())
#去除左边的空格
print(str.rstrip())
#去除右边的空格
print(str.replace(' ',''))
#去除字符串全部空格
str = '123' \
      '456'
print(str.replace('\n',''))
#去除换行
print(str.replace('\r',''))
#去除换行
print(str.replace('\n', '').replace('\r', ''))

Guess you like

Origin blog.csdn.net/sgsdsdd/article/details/112722738