新聞中心
大家應(yīng)該知道python中print之后是默認(rèn)換行的,

創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),邵原網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:邵原等地區(qū)。邵原做網(wǎng)站價(jià)格咨詢:18980820575
那如何我們不想換行,且不想講輸出內(nèi)容用一個(gè)print函數(shù)輸出時(shí),就需要改變print默認(rèn)換行的屬性,
方法如下:
print('contents', end='!@#$%^&*')end就表示print將如何結(jié)束,默認(rèn)為end="\n"(換行)
栗子:
print("祝各位身體健康")
print("!")
print("祝各位身體健康", end=' ')
print("!")python3.0 的print 函數(shù)有如下的形式:
print([object,...][,seq=' '][,end='\n'][,file=sys.stdout])
我們在使用print()函數(shù)時(shí),并不希望輸出結(jié)束后自動(dòng)換行,因此,我們可以按照下面的方法來做
1.print()指定結(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é)尾字符。
python學(xué)習(xí)網(wǎng),免費(fèi)的python學(xué)習(xí)網(wǎng)站,歡迎在線學(xué)習(xí)!
分享標(biāo)題:創(chuàng)新互聯(lián)Python教程:python中print如何不換行
鏈接分享:http://www.dlmjj.cn/article/dpejiie.html


咨詢
建站咨詢
