1.利用for循环
for i in range(1,10):
for m in range(1,i+1):
print(m,'*',i,'=',m*i,end=' ')
print('\r')
2.改进的for 循环:
for x in range(1,10):
for y in range(1,x+1):
print(f'{x}*{y}={x*y}',end='\t')
print('\r')
3.利用join和占位符:
print('\n'.join([' '.join(['%s*%s=%s'%(y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
4.利用f-string(Python 3.6版本以后可以用)
print('\n'.join([' '.join([f'{y}*{x}={y*x}' for y in range(1,x+1)]) for x in range(1,10)]))