使用列表推倒式制作九九乘法表
#方法1
list = [0,1,2,3,4,5,6,7,8,9]
result = [str(j) + ‘*’ + str(i) + ’=’ +str(i*j) for i in list for j in list if i >=j]
print(result)
#方法2
result = [str(j) + '*' + str(i) + '=' + str(i*j) for i in range(1,10) for j in range(1,10) if i >= j]
print(result)
Python学习交流、资源共享群:563626388 QQ