a.去除左端空格 lstrip()
str0='abcdef'
str1=' abcdef'
print(str0)
print(str1.lstrip())
b.去除右端空格 rstrip()
str0='abcdef '
str1='abcdef '
print(str0)
print(str1.rstrip())
c.去除两端空格 strip()
str0=' abcdef '
str1=' abcdef '
print(str0)
print(str1.strip())
str0=' a b c d e f '
str1=' a b c d e f '
print(str0)
print(str1.replace(' ',''))
str0=' a b c d e f '
str1=' a b c d e f '
print(str0)
print(''.join(str1.split()))
import re
str0=' a b c d e f '
str1=' a b c d e f '
print(str0)print(re.sub(' ','',str1))
[1] https://www.cnblogs.com/146xwq/p/9684891.html
原文:https://www.cnblogs.com/TianchiLiu/p/10262598.html