![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
学习知识点:
1. string.join(seq): 以string字符串作为分隔符,将seq的所有元素拼接成一个新的字符串
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9Db250cmFjdGVkQmxvY2suZ2lm.gif?w=700&webp=1)
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm.gif?w=700&webp=1)
1 s = ['%d * %d = %d' % (y, 4, 4*y) for y in range(1, 5)]
2 print('\t'.join(s))
3
2. list的赋值可以采用表达式
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9Db250cmFjdGVkQmxvY2suZ2lm.gif?w=700&webp=1)
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm.gif?w=700&webp=1)
1 s = ['%d * %d = %d' % (y, 4, 4*y) for y in range(1, 5)]
下面是99乘法表的拆分过程
1. 打印第i行
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9Db250cmFjdGVkQmxvY2suZ2lm.gif?w=700&webp=1)
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm.gif?w=700&webp=1)
1 i = 5
2 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
3 print('\t'.join(s))
2. 打印多行
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9Db250cmFjdGVkQmxvY2suZ2lm.gif?w=700&webp=1)
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm.gif?w=700&webp=1)
1 i = 1
2 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
3 print('\t'.join(s))
4 i = 2
5 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
6 print('\t'.join(s))
7 i = 3
8 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
9 print('\t'.join(s))
3. 再次借助join的方式实现
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9Db250cmFjdGVkQmxvY2suZ2lm.gif?w=700&webp=1)
![【Pthon入门学习】99乘法表 【Pthon入门学习】99乘法表](https://image.shishitao.com:8440/aHR0cHM6Ly9pbWFnZXMuY25ibG9ncy5jb20vT3V0bGluaW5nSW5kaWNhdG9ycy9FeHBhbmRlZEJsb2NrU3RhcnQuZ2lm.gif?w=700&webp=1)
1 i = 1
2 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
3 # print('\t'.join(s))
4 i = 2
5 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
6 # print('\t'.join(s))
7 i = 3
8 s = ['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]
9 # print('\t'.join(s))
10
11 print('\n'.join('\t'.join(s) for i in range(1, 10)))
12 #将s替换成表达式后即为99乘法表
13 print('\n'.join('\t'.join(['%d * %d = %d' % (y, i, y * i) for y in range(1, i+1)]) for i in range(1, 10)))
14
15