通过help(print)命令可以查看到详细的帮助信息

Help on built-in function print in module builtins:

print(…) print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.

一个例子熟练Print()函数的参数用法:

1
2
 with open('abc.txt','w') as f:
     print("file\n","abc","fff",sep='#########\n',end='',file=f)

运行,会输出以下内容到abc.txt中:

file
#########
abc#########
fff

flush 参数默认为false,如果指定flush = True,那么会即时彻底执行print()函数,而不是先将内容存放在内存中。