您的位置:首页 > 编程语言 > Python开发

Python打印print函数深入解析

2016-07-17 01:17 531 查看

Python的print函数细节

 尊重劳动成果,请访问CSDN著者原文链接 http://blog.csdn.net/zixiao217/article/details/51929078

 学会在IDLE中使用help(BIF)命令查看BIF的说明

>>> 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.


上面的代码通过help(print)查看BIF print的用法以及说明:

print的效用:Prints the values to a stream, or to sys.stdout by default.—将值以流的形式输出,或者使用默认打印在控制台

print函数参数列表:

参数说明
value是要打印的值
值列表,表示可以一次性打印多个值
sepstring inserted between values, default a space.——表示打印值时,各个值之间的间隔符,默认是一个空白字符
endstring appended after the last value, default a newline.——打印完最后一个值需要添加的字符串,默认是换行符,即打印完会跳到新行
filea file-like object (stream); defaults to the current sys.stdout.——将值打印到一个文件流对象,默认是打印到控制台
flushwhether to forcibly flush the stream.——是否强制冲刷流
打印多个值示例:

>>> print("值一", "值二", "值三")
值一 值二 值三
>>> print("字符串", 2, 1 + 2j)   # 同时打印字符串、int、复数
字符串 2 (1+2j)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: