python3.4中的print怎么不换行
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学习网!
本网站文章仅供交流学习 ,不作为商用, 版权归属原作者,部分文章推送时未能及时与原作者取得联系,若来源标注错误或侵犯到您的权益烦请告知,我们将立即删除.