Python print() 函數在屏幕或其他標準輸出設備上打印給定對象。
簽名
print(object(s), sep=separator, end=end, file=file, flush=flush)
參數
object(s):它是要打印的對象。符號 * 表示可能有多個對象。
sep='separator'(可選):對象由sep分隔。 sep 的默認值為“ ”。
end='end'(可選):決定最後打印哪個對象。
文件(可選): - 文件必須是具有 write(string) 方法的對象。如果省略,將使用 sys.stdout 在屏幕上打印對象。
刷新(可選):如果為 True,則強製刷新流。 flush 的默認值為 False。
返回
它不返回任何值。
Python print() 函數示例 1
下麵的例子顯示了 print() 的工作。
print("Python is programming language.")
x = 7
# Two objects passed
print("x =", x)
y = x
# Three objects passed
print('x =', x, '= y')
輸出:
Python is programming language. x = 7 x = 7 = y
說明:
在上麵的代碼中,隻有 objects 參數被傳遞給 print() 函數(在所有三個打印語句中)。
結束參數 '\n'(換行符)用於在下一行顯示輸出,默認情況下。正如我們所見,每個打印語句都在新行中顯示輸出。
如果文件保存為 sys.stdout,則輸出將打印在屏幕上。
這裏flush的值為False,所以不會強製刷新流。
Python print() 函數示例2
下麵的示例使用帶有分隔符和結束參數的 print()。
x = 7
print("x =", x, sep='00000', end='\n\n\n')
print("x =", x, sep='0', end='')
輸出:
a =000007 a =07
相關用法
- Python print()用法及代碼示例
- Python string printable()用法及代碼示例
- Python calendar prmonth()用法及代碼示例
- Python calendar pryear()用法及代碼示例
- Python property()用法及代碼示例
- Python pandas.bdate_range()用法及代碼示例
- Python plotly.figure_factory.create_annotated_heatmap()用法及代碼示例
- Python PIL putpixel()用法及代碼示例
- Python plotly.figure_factory.create_choropleth()用法及代碼示例
- Python PIL putalpha()用法及代碼示例
- Python plotly.express.line()用法及代碼示例
- Python Numpy polynomial legint()用法及代碼示例
- Python plotly.figure_factory.create_dendrogram()用法及代碼示例
- Python pandas.DataFrame.T()用法及代碼示例
- Python plotly.figure_factory.create_2d_density()用法及代碼示例
- Python pandas.eval()用法及代碼示例
- Python pow()用法及代碼示例
- Python PIL paste() and rotate()用法及代碼示例
- Python plotly.express.scatter_ternary()用法及代碼示例
- Python plotly.figure_factory.create_bullet()用法及代碼示例
注:本文由純淨天空篩選整理自 Python print() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。