记录一些学习 Python 过程中遇到的问题。
Print () 函数的高级用法
通过 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 | with open('abc.txt','w') as f: |
运行,会输出以下内容到 abc.txt
中:
1 | file |
flush
参数默认为 false,如果指定 flush = True
,那么会即时彻底执行 print()
函数,而不是先将内容存放在内存中。