1.2.3.2 for/range

在索引上迭代:

In [97]:

  1. for i in range(4):
  2. print(i)
  1. 0
  2. 1
  3. 2
  4. 3

但是最经常使用,也更易读的是在值上迭代:

In [98]:

  1. for word in ('cool', 'powerful', 'readable'):
  2. print('Python is %s' % word)
  1. Python is cool
  2. Python is powerful
  3. Python is readable