摘要:關(guān)于Python2.x和3.x帶來(lái)的print不換行的問(wèn)題:昨天有發(fā)過(guò)推文,利用end = 定義,解決了橫向的小問(wèn)題,但是由于屏幕顯示的問(wèn)題,若字符串長(zhǎng)度過(guò)大,則會(huì)引起不便。兩個(gè)或多個(gè)print做分割的情況下,如何保持依然橫向輸出,一般的是在print尾部加上逗號(hào)(,)但是在3.x下,則不行,需要使用end = "(something)",some signs like , .
關(guān)于Python2.x和3.x帶來(lái)的print不換行的問(wèn)題:昨天有發(fā)過(guò)推文,利用end = 定義,解決了橫向的小問(wèn)題,但是由于屏幕顯示的問(wèn)題,若字符串長(zhǎng)度過(guò)大,則會(huì)引起不便。兩個(gè)或多個(gè)print做分割的情況下,如何保持依然橫向輸出,一般的是在print尾部加上逗號(hào)(,)但是在3.x下,則不行,需要使用end = "(something)",some signs like , . ; 'also you can put a word or str in"".
Example:
############################################ 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 test All 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 ,
更多關(guān)于python中print的不換行即時(shí)輸出的快速解決方法請(qǐng)關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其他文章!