python学习 (二十八) Python的for 循环

1: for 循环可以循环如下类型:

my_string = "abcabc"        // 字符串类型
for c in my_string:
    print(c, end=' ')

cars = ['aa','bb','cc']     // list类型
for car in cars:
    print(car)

d = {'one':1, "tow":2}      // 字典类型, 
for key in d:               // 默认是key
    print(key + " " + str(d[key]))

t = (1, 2, 3)               // 元组
for item in t:
print(item)

 2 循环多个

  zip函数:打包

l1 = [1, 2, 3]
l2 = [6, 7, 8, 20]
for k in zip(l1, l2):
    print(k)

result:

  (1, 6)
  (2, 7)
  (3, 8)

 

posted @ 2018-10-27 19:48  刘大飞  阅读(211)  评论(0编辑  收藏  举报