去除空格
1 strip(),去除字符串开头或者结尾的空格
a = " ab cd ef "
print(a.strip())
>>>ab cd ef
2 lstrip(),去除字符串头部的空格
a = " ab cd ef "
print(a.lstrip())
>>>ab cd ef
3 rstrip(),去除字符串尾部空格
a = " ab cd ef "
print(a.rstrip())
>>> ab cd ef
4 replace,去除全部空格
a = " ab cd ef "
print(a.replace(" ", ""))
>>>abcdef
5 join()+split()方法,去除全部空格
a = " ab cd ef "
b = a.split() # b为['va', 'bc', 'de']
c = "".join(b)
>>>abcdef