Python3 print 不换行

本文主要介绍在Python3 下 print 实现不换行的效果。

Python 3.x

在 Python 3.x 中,我们可以在 print() 函数中添加 end="" 参数,这样就可以实现不换行效果。

在 Python3 中, print 函数的参数 end 默认值为 "\n",即end="\n",表示换行,给 end 赋值为空, 即end="",就不会换行了,例如:

Python3.x 实例

print('这是字符串,', end="")
print('这里的字符串不会另起一行')

执行以上代码,输出结果为:

这是字符串,这里的字符串不会另起一行

end="" 可以设置一些特色符号或字符串:

实例

print('12345', end=" ")  # 设置空格
print('6789')

print('839870068', end="@")  # 设置符号
print('qq.com')

print('bing ', end="bilfun. ")  # 设置字符串
print('com')

执行以上代码,输出结果为:

12345 6789
[email protected]
bing bilfun. com

你可能感兴趣的:(开源文档,python,开发语言)