请看示例:
一行实现99乘法表:
print(' '.join([' '.join(['%s*%s=%-2s' % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)]))
简单版本
1 first = 1 #被乘数初始值 2 #second = 9 3 while first <= 9: 4 #print(str(first)+"*"+str(first)+"=",first) 5 sec = 1 #乘数初始值 6 while sec <= first: #9*9时结束 #end=" " = 换行 = tab键 7 print(str(sec),'*',str(first),'=',(str(sec * first)),end=" ") #用,隔开中间有距离,+则没有 8 sec += 1 9 print() #另起一行的作用 10 first += 1