python:printとformat

936 ワード

クエリーヘルプ:help(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印刷多値はカンマで区切られ、区切り記号はデフォルトでスペース(sep=')、新しい行記号は'''
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