代码示例:
import sys
information = [
'Python由荷兰数学和计算机科学研究学会的Guido van Rossum 于1990 年代初设计,',
'作为一门叫做ABC语言的替代品。',
'Python提供了高效的高级数据结构,还能简单有效地面向对象编程。',
"Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的编程语言,",
'随着版本的不断更新和语言新功能的添加,逐渐被用于独立的、大型项目的开发。',
]
with open("打印输出.txt",'w')as file:
for info in information:
print(info,file=file) # 打印到指定文件
# print(info,file=file,end='') # 打印到指定文件
# print(info,file=sys.stdout) # 打印到标准输出(控制台cmd)
print('AAA','BBB','CCC',file=file,end='\n###\n',sep='***')
print(file=file)
print('111',file=file,end=' ')
print('222',file=file,end=' ')
print('333',file=file,end=' ')
演示效果: