Python输出出现多于空格的问题

Python输出出现多于空格的问题

在我的实践中,有一种情况叫输出中出现多余的空格:

比如我想输出hello,xxx!会输出成hello,xxx !

eg:

>>> L = ['bart','lisa','adam']

>>> for i in L:

print('hello,',i,'!')

hello, bart ! #出现多余空格

hello, lisa !

hello, adam !

改进:

1、使用格式化输出:

>>> L = ['bart','lisa','adam']

>>> for i in L:

print('hello,%s!'%i)

hello,bart!

hello,lisa!

hello,adam!

2、使用连接运算符(+)

>>> L = ['bart','lisa','adam']

>>> for i in L:

print('hello,'+i+'!')

hello,bart!

hello,lisa!

hello,adam!

相关推荐

陌陌在什么地方能看到自己的动态 陌陌个人动态查看方法
365名品汇个人注册推荐码

陌陌在什么地方能看到自己的动态 陌陌个人动态查看方法

08-12 👁️ 4228
大众车钥匙怎么拆开换电池?
365名品汇个人注册推荐码

大众车钥匙怎么拆开换电池?

09-08 👁️ 8384
布冯退役后踢过98世界杯的只剩2人!球迷:还有一人有些可惜