如何在Python2.7中使用Python3.5中的语法end=

print(“anything”,end=”anything”)是Python3.5中的语法,想在2.7中使用,就需要在首行添加from future import print_function
下面是九九乘法表例子:

from __future__ import print_function
num1 = 1
num2 = 1
while num1<=9:
    num2=1
    while num2<=num1:
        print(str(num2)+"*"+str(num1)+"="+str(num1*num2),end="\t")
        num2+=1
    print()
    num1+=1

你可能感兴趣的:(Python)