2、python基礎---輸出

print() 是一種內置函數,用于將指定的數據輸出到控制臺或文件中。
print() 函數的語法如下:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
其中:
objects:要打印的一個或多個對象,用逗號隔開。
sep:指定多個對象之間用什么字符分隔,默認為一個空格。
end:指定打印完所有對象之后要添加的字符,默認為一個換行符。
file:指定打印輸出到的文件對象,默認為 sys.stdout,即控制臺。
flush:如果為 True,則立即將輸出緩沖區(qū)中的內容刷新到文件中,否則等待緩沖區(qū)滿后再刷新。
例如:
print('hello', 'world') ?# 輸出:
hello worldprint('hello', 'world', sep=',') ?# 輸出:hello,world
print('hello', 'world', end='!') ?# 輸出:hello world!
print('hello' + 'word')? # 輸出:?helloword
print('hello' *2)? ? ?# 輸出:hellohello
標簽: