python3之print()函数

1、函数:
def print(self, *args, sep=' ', end=' ', file=None): # known special case of print

"""
print(value, ..., sep=' ', end=' ', 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.
"""
2、file参数应用:
  with open('filename','w') as f:#必须要有写权限
    print('123',file=f)#把123写入到filename文件中
3、格式化输出:
print('%d+%d=%d' % (x,y,z))
原文地址:https://www.cnblogs.com/Inbreeze/p/14095670.html