python输出怎么不要空格

Python (206) 2023-07-10 09:36:07

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'
THE END

发表回复