新聞中心
Python中輸出主要是使用print()函數(shù)。Python2和Python3中的函數(shù)是有區(qū)別的。我們?cè)谑褂胮rint()函數(shù)時(shí),并不希望輸出結(jié)束后自動(dòng)換

行。
1print()指定結(jié)束符
print('hello',end='')
print('world')
#result:helloworld當(dāng)print()函數(shù),指定end參數(shù)為空字符后,print()函數(shù)就不再主動(dòng)添加換行符了。并且,hello和world之間也不存在任何空格。
a = 'first line' b = 'second line' c = 'third line' print(a,end='\n\n') print(b) print(c,end='!')
我們可以利用指定結(jié)束符的方法,靈活控制換行行數(shù)和結(jié)尾字符。
2.print()函數(shù)
知道了如何實(shí)現(xiàn)輸出不換行,下面我們來(lái)看一下原理。
print()函數(shù)的形式是:
print(*objects, sep=' ', end='\n', file=sys.stdout,flush=False)
objects -- 復(fù)數(shù),表示可以一次輸出多個(gè)對(duì)象。輸出多個(gè)對(duì)象時(shí),需要用 , 分隔。
sep -- 用來(lái)間隔多個(gè)對(duì)象,默認(rèn)值是一個(gè)空格。
end -- 用來(lái)設(shè)定以什么結(jié)尾。默認(rèn)值是換行符 \n,我們可以換成其他字符串。
file -- 要寫(xiě)入的文件對(duì)象。
flush--是否要強(qiáng)行刷新stream。
python學(xué)習(xí)網(wǎng),大量的免費(fèi)python學(xué)習(xí)視頻,歡迎在線(xiàn)學(xué)習(xí)!
文章題目:創(chuàng)新互聯(lián)Python教程:python3.5怎么不換行輸出
本文路徑:http://www.dlmjj.cn/article/cdpcgjj.html


咨詢(xún)
建站咨詢(xún)
