python 一条语句生成九九乘法表并格式化

print('\n'.join(['\t'.join(["%s *%2s =%+3s" % (j, i, i * j) if j != 1 else "%s *%2s =%+2s" % (j, i, i * j) for j in range(1, i + 1)]) for i in range(1, 10)]))
# 打印 99 乘法表

print('\n'.join(['\t'.join(["%s *%2s =%+3s" % (j, i, i * j) if j != 1 else "%s *%2s =%+2s" % (j, i, i * j) for j in range(1, i + 1)]) for i in range(1, 10)]))

  

效果

 

posted @ 2022-08-03 12:05  yinzhuoqun  阅读(54)  评论(0编辑  收藏  举报