print()与sys.stdout.write()区别
stdout只能输出字符串,如果要输出数字,也需要先转成字符串形式的;print可以直接输出各种类型。
stdout输出结果后不自动换行;print会自动换行。
print默认调用了sys.stdout.write()方法将输出打印到控制台,也可通过file参数将输出打印到其他文件中
f = open(‘test.txt’,‘a’)
print(‘this is a test’,file=f)
————————————————
版权声明:本文为CSDN博主「chuang94」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_35834894/article/details/115234334