內置函式print()用于輸出資訊到標準控制臺或指定檔案,語法格式為:
print(value1,value2,... , sep=' ', end='\n', file=sys.stdout, flush=False)
sep引數之前為需要輸出的內容(可以有多個);
sep引數用于指定資料之間的分隔符,默認為空格;
end引數用于指定輸出玩資料之后在輸出什么字符;
file引數用于指定輸出位置,默認為標準控制臺,也可以重定向輸出到檔案,
>>> print(1,3,5,7,sep='\t') #修改默認分隔符
1 3 5 7
>>> for i in range(10): #修改end引數,每個輸出之后不換行
print(i,end='')
0123456789
>>> with open ('test.txt','a+')as fp:#重定向,將內容輸出到檔案中
print('Hello world!',file=fp)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/170387.html
標籤:Python
上一篇:實體008:九九乘法表
