#!/usr/bin/env python3
# -*- coding: utf-8 -*-
d = {'Michael': 95,'Bob': 75,'Tracy': 85}
for key in d:
print(key)
for ch in 'ABCD':
print(ch)
# 判断是否可以进行迭代
from collections import Iterable
print('\'ABCD\'','is Iterable?? :',isinstance('ABCD',Iterable))
print('123 is Iterable?? :',isinstance(123,Iterable))
# 迭代时使用下标
for i,value in enumerate(['A','B','C']):
print(i,value)
for x,y in [(1,2),(3,4),(5,6)]:
print(x,y)
Python练习-- iterator
最新推荐文章于 2018-08-21 13:22:50 发布
本文介绍了Python编程中使用字典、字符串迭代的基础知识,并通过实例展示了如何在迭代过程中使用下标和元组来获取元素。
3367

被折叠的 条评论
为什么被折叠?



