默认情况下,python的print()函数以换行符结尾。有C/C++背景的程序员可能想知道如何在没有换行符的情况下打印。
null
Python的print()函数带有一个名为“end”的参数。默认情况下,此参数的值为’,即新行字符。可以使用此参数以任何字符/字符串结束打印语句。
# This Python program must be run with # Python 3 as it won't work with 2.7. # ends the output with a <space> print ( "Welcome to" , end = ' ' ) print ( "GeeksforGeeks" , end = ' ' ) |
输出:
Welcome to GeeksforGeeks
还有一个程序演示终端参数的工作。
# This Python program must be run with # Python 3 as it won't work with 2.7. # ends the output with '@' print ( "Python" , end = '@' ) print ( "GeeksforGeeks" ) |
输出:
Python@GeeksforGeeks
本文由 安基特·宾达尔 .如果你喜欢GeekSforgek,并且想贡献自己的力量,你也可以写一篇文章,并将文章邮寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写评论
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END