Python学习第一章第五天

  • Post author:
  • Post category:python



for循环和可迭代对象的遍历

for x in (1,2,3)

可迭代对象可以是:

列表,元组,字符串,,字典,迭代器对象(iterator),生成器函数(generator),文件对象

range对象:

range对象可以传递 ‘步长’

九九乘法表的嵌套循环的练习

for x in range(1,10):
    for y in range(1,x+1):
        print("{0}*{1} = {2}".format(x,y,(x*y)),end="\t")
    print()

#得出的结果
'''
1*1 = 1	
2*1 = 2	2*2 = 4	
3*1 = 3	3*2 = 6	3*3 = 9	
4*1 = 4	4*2 = 8	4*3 = 12	4*4 = 16	
5*1 = 5	5*2 = 10	5*3 = 15	5*4 = 20	5*5 = 25	
6*1 = 6	6*2 = 12	6*3 = 18	6*4 



版权声明:本文为qq_64852881原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。