Python syntax: detailed explanation of print function
Syntax format:
print(value1,value2,……,sep=' ',end='\n',file=sys.stdout,flush=False)
Optional keyword parameters:
file:类文件对象(stream);默认为当前的sys.stdout.
sep:在值之间插入的字符串,默认为空格。
end:在最后一个值后附加的字符串,默认为换行符。
flush:是否强制刷新流。
1. Sep: default is a space
print('1','2','3','4',sep=',')
Output result:
1,2,3,4
2, end: the default is newline\n
print('1','2','3',end='结束了')
Output result: (note that there is no space between 3 and'end over')
1 2 3结束了
3、file
The default value of the file parameter sys.stdout
represents the system standard output, which is the screen. You can modify the value of this parameter and output it to a specific file.
f = open(r"read.txt","w") #打开文件
print('test',file=f) #输出到文件
f.close() #关闭文件
4、flush
The flush parameter is used to control the output cache. Generally, in order to obtain better performance, keep it as False.