ITPub博客

首页 > IT职业 > IT职场 > python怎么不转行输出

python怎么不转行输出

IT职场 作者:nt1979 时间:2021-09-11 10:22:08 0 删除 编辑

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

1.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='nn')
print(b)
print(c,end='!')

更多学习内容,请点击Python学习网!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4822/viewspace-2834576/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-05

  • 博文量
    318
  • 访问量
    17318