问题
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