教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python输出怎么不要空格

python输出怎么不要空格

发布时间:2021-03-18   编辑:jiaochengji.com
教程集为您提供python输出怎么不要空格等资源,欢迎您收藏本站,我们将为您提供最新的python输出怎么不要空格资源

python输出不要空格的方法:

1、strip()方法,去除字符串开头或者结尾的空格

>>> a = " a b c "
>>> a.strip()
'a b c'

2、lstrip()方法,去除字符串开头的空格

>>> a = " a b c "
>>> a.lstrip()
'a b c '

3、rstrip()方法,去除字符串结尾的空格

>>> a = " a b c "
>>> a.rstrip()
' a b c'

4、replace()方法,可以去除全部空格

>>> a = " a b c "
>>> a.replace(" ", "")
'abc'

您可能感兴趣的文章:
python输出怎么不要空格
python中制表符是什么意思
python缩进有什么用
Python怎么让输出在一行
python怎么打印字符
python语言采用严格的什么
python怎么输入多行
python怎么打印变量
python怎么输出列表
python怎么打印菱形

[关闭]
~ ~