print 方法默认调用 sys.stdout.write 方法,即往控制台打印字符串。
当然二者也有区别:1.sys.stdout.write()结尾没有换行,而print()是自动换行的。2.write()只接收字符串格式的参数3.print()能接收多个参数输出,write()只能接收一个参数。以下是区别代码:
def Inface_Test():
print("这是print")
sys.stdout.write("这是")
sys.stdout.write("write")
本文探讨了Python中print方法与sys.stdout.write方法的区别,包括换行行为、参数接收和应用场景。通过实例演示了两者在实际操作中的不同之处。
31万+

被折叠的 条评论
为什么被折叠?



