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.
>>>