ITPub博客

首页 > IT职业 > IT职场 > python3.4中的print怎么不换行

python3.4中的print怎么不换行

IT职场 作者:becaso 时间:2021-09-11 10:26:41 0 删除 编辑

python中print之后是默认换行的,那如何我们不想换行,且不想讲输出内容用一个print函数输出时,就需要改变print默认换行的属性,

方法如下:

print('contents', end='!@#$%^&*')

end就表示print将如何结束,默认为end="n"(换行)

栗子:

print("祝各位身体健康")
print("!")
print("祝各位身体健康", end=' ')
print("!")

python3.0 的print 函数有如下的形式:

print([object,...][,seq=' '][,end='n'][,file=sys.stdout])

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

1.print()指定结束符

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

我们可以利用指定结束符的方法,灵活控制换行行数和结尾字符。

学习python,尽在python学习网!

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

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

注册时间:2019-04-16

  • 博文量
    104
  • 访问量
    935