Python的print打印輸出不換行

python的print默認帶換行,剛學自己不會,度了下,發現這個好用:

開頭加(python v3.7下測試不需要這條):

from __future__ import print_function

print輸出是加“,end='' ”:

print(xx,end=' ')

eg:

from __future__ import print_function
#九九乘法口訣表
for x in range(0,10):
    for y in range(1,x+1):
        print(str(y)+"*"+str(x)+"="+str(x*y),end=' ')
    print("")

DemodeMacBook-Air:~ demo$ python

Python 2.7.10 (default, Jul 15 2017, 17:16:57) 

[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章