这里记录一下我在学习Python过程中总结的一些小知识点,这些知识点可能是平时我们以为自己明白了但是又没有真正弄明白的点。
1. print()函数
这个函数我们用的太多了,但是仔细看这个函数又不简单。首先看一下Python手册对这个函数的描述:
Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
Changed in version 3.3: Added the flush keyword argument.
以上摘自于Python手册对于print函数的描述,我们这里说两点:参数sep和end。