python输出怎么不要空格
发布时间:2025-02-27 18:36:19

Python输出不空格的方法:
1、strip()方法,去除字符串开头或结尾的空格
>>>a="abc" >>>a.strip() 'abc'
2、lstrip()方法,去除字符串开头的空格
>>>a="abc" >>>a.lstrip() 'abc'
3、rstrip()方法,去除字符串结尾的空格
>>>a="abc" >>>a.rstrip() 'abc'
4、replace()方法可以去除所有空间
>>>a="abc"
>>>a.replace("","")
'abc' 