标签:
>>> squares[:]
[1, 4, 9, 16, 25]
>>> for i, v in enumerate([‘tic‘, ‘tac‘, ‘toe‘]): ... print(i, v) ... 0 tic 1 tac 2 toe
>>> questions = [‘name‘, ‘quest‘, ‘favorite color‘] >>> answers = [‘lancelot‘, ‘the holy grail‘, ‘blue‘] >>> for q, a in zip(questions, answers): ... print(‘What is your {0}? It is {1}.‘.format(q, a)) ... What is your name? It is lancelot. What is your quest? It is the holy grail. What is your favorite color? It is blue.
>>> knights = {‘gallahad‘: ‘the pure‘, ‘robin‘: ‘the brave‘} >>> for k, v in knights.items(): ... print(k, v) ... gallahad the pure robin the brave
标签:
原文地址:http://www.cnblogs.com/garyang/p/5505607.html