Python

print()

通过输入 help(print) 得到 print 内建函数的参数

Help on built-in function print in module builtins:

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.

print() 函数的几个参数:

  • value 是值的意思,可以传出字符串、数字、列表等
  • sep 默认为空格,在打印的时候两个值之间填充空格
  • end 默认是换行,当不想要换行显示的时候可以修改默认值
  • file 表示了 print 和 sys.stdout 的关系,print 函数默认已经是标准化输出
  • flush 是刷新的意思
'''
使用一个循环容易看出效果,分隔符用 123 代替,默认的换行改成了制表符,可以看到打印之后光标没有到下一行
'''
>>> for i in range(2):
     print("hello", "world", sep='123', end='	')

hello123world   hello123world   >>>

这里有一篇有趣的文章,通过调整 flush 参数实现动态图的效果python的print(flush=True)实现动态loading......效果

原文地址:https://www.cnblogs.com/chenxianbin/p/10597755.html