關(guān)于Python2.x和3.x帶來的print不換行的問題:昨天有發(fā)過推文,利用end = 定義,解決了橫向的小問題,但是由于屏幕顯示的問題,若字符串長度過大,則會引起不便。兩個或多個print做分割的情況下,如何保持依然橫向輸出,一般的是在print尾部加上逗號(,)但是在3.x下,則不行,需要使用end = "(something)",some signs like , . ; 'also you can put a word or str in"".
############################################end1 = "j"end2 = "u"end3 = "s"end4 = "t"end5 = "t"end6 = "e"end7 = "s"end8 = "t"print(end1 + end2 + end3 + end4,end = " ")print(end5 + end6 + end7 + end8)############################################Explain:You can see that i put space between""There will be something in your screen:just testAll the codes was run in python 3.2,if you write the codes in pythons 2.x,like python2.7, ##################################################end1 = "j"end2 = "u"end3 = "s"end4 = "t"end5 = "t"end6 = "e"end7 = "s"end8 = "t"print(end1 + end2 + end3 + end4,)print(end5 + end6 + end7 + end8)#################################################that's all,in python 2.x so the differences is:3.2 end = " "2.7 ,
以上這篇python中print的不換行即時輸出的快速解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選