查询帮助:
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 打印多值以逗号分隔,分隔符默认是空格(sep=‘ ’),新行符是‘\n’
print(5,6,sep='>>')
5>>6
print(5,6,sep='>>',end='---')
print(8)
5>>6---8
{}代表format中的值,{0}代表第一个
print(' {} {}aa{}'.format(1,2,3))
1 2aa3
print(' {2} {2}aa{2}'.format(1,2,3))
3 3aa3
本文详细解析了Python中print函数的使用方法,包括参数说明、默认行为及如何自定义分隔符和结束符。通过实例展示了如何利用format进行字符串格式化,以及位置参数的灵活运用。
2202

被折叠的 条评论
为什么被折叠?



