品易云推流 关闭
文章详情页
文章 > Python常见问题 > python输出怎么连在一起

python输出怎么连在一起

头像

silencement

2020-01-09 11:40:453665浏览 · 0收藏 · 0评论

使用print()函数时,并不希望输出结束后自动换行,因此,我们可以按照下面的方法来做

print()指定结束符

print('hello',end='')
print('world')
#result:helloworld

当print()函数,指定end参数为空字符后,print()函数就不再主动添加换行符了。并且,hello和world之间也不存在任何空格。

a = 'first line'
b = 'second line'
c = 'third line'
print(a,end='\n\n')
print(b)
print(c,end='!')

推荐学习《python教程》。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图