items = [11, 22, 33, 44, 55, 66]

遍历数组

for item in items:
    print(item)

遍历数组和下标

for i, item in enumerate(items):
    print(i, item)

遍历字典keys

dicts = {"A": 1, "B": 2, "C": 3}
for dic in dicts:
    print(dic)
for k in dicts.keys():
    print(k)

遍历字典values

for v in dicts.values():
    print(v)

遍历字典的key-value

for k, v in dicts.items():
    print(k, v)

简化循环代码

result = []
for i in items:
    result.append(i)
print(result)
# 列表推导式 list comprehension
result2 = [i + 1 for i in items]
print(result2)
# 使用内置函数map与匿名函数lambda
result2 = map(lambda i: i + 1, items)
print(dict(result2))