日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

在python3中print作为函数存在_Python3中的print函数

發(fā)布時間:2023/12/31 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在python3中print作为函数存在_Python3中的print函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python3中的輸出語句:

函數(shù)原型如下:

print(help(print)) 使用此語句打印

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.

分隔符:

a = 'hello'b = 'Python'c = 'ixusy88' # 默認空格print('1----',a,b,c) # 指定分割符print('2----',a,b,c,sep='!') print('3----',a,b,c,sep=',') """輸出結果:1---- hello Python ixusy882----!hello!Python!ixusy883----,hello,Python,ixusy88"""

end:

a = 'hello'b = 'Python'c = 'ixusy88' # end 默認是新的一行,即下一個打印會在新的一行輸出print('1----',a,b,c) # 指定結束符,print('2----',a,b,c,end='###')print('3----',a,b,c)print('4----',a,b,c) """結果:1---- hello Python ixusy882---- hello Python ixusy88###3---- hello Python ixusy884---- hello Python ixusy88"""

輸出流:

a = 'hello'b = 'Python'c = 'ixusy88' # file ,默認是sys.stdoutprint('1----',a,b,c) # file,指定輸出流,輸出到文件中print('2----',a,b,c,file=open('test.txt','w'))print('-1--')# 讀取文件,并打印出來print(open('test.txt').read() )print('-2--') # 也可以修改sys.stdout,把定向到一個文件,之后的所有輸出都會保存到文件中;import sysprint('sys.stdout之后')sys.stdout = open('test_2.txt','w')print('1----',a,b,c)print(sys.platform) """輸出結果:1---- hello Python ixusy88-1--2---- hello Python ixusy88-2--sys.stdout之后"""

輸出文件中的內容

總結

以上是生活随笔為你收集整理的在python3中print作为函数存在_Python3中的print函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。