首页 > 编程语言 > 详细

二十八 Python的for 循环

时间:2018-10-27 20:47:35      阅读:141      评论:0      收藏:0      [点我收藏+]

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)

 

二十八 Python的for 循环

原文:https://www.cnblogs.com/liufei1983/p/9863057.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!