python print及格式化

时间:2023-03-08 22:39:04
  • print(value,sep=' ',end='\n',file=sys.stdout, flush=False)

sep=' '默认空格


print('hello','world')
#hello world
print('hello','world',sep='|')
#hello|world

end='\n'默认换行符

print('hello')
print('world')
#hello
#world print('hello',end=' ')
print('world')
#hello world

file=sys.stdout默认输出到 系统的标准输出

with open(r'd:\test.txt', 'w') as txt:
print('abc',file=txt)
#输出字符串'abc'到D盘test.txt文件

flush=False

....