Is it possible to print without using the print function in Python?

一个人想着一个人 提交于 2020-07-03 08:08:19

问题


I wondered whether it is possible to print (for example a string) in Python without the print function. This can be done by a command or by some trick.

For example, in C there are printf and puts.

Can someone show me a way to print or to deny this possibility?


回答1:


sys.stdout.write("hello world\n")



回答2:


import sys
sys.stdout.write("hello")



回答3:


You can use

sys.stdout.write()

Sometimes I find sys.stdout.write more convenient than print for printing many things to a single line, as I find the ending comma syntax of print for suppressing the newline inconvenient.



来源:https://stackoverflow.com/questions/21216560/is-it-possible-to-print-without-using-the-print-function-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!