python学习笔记 - for循环:遍历列表, 打印索引和元素

#遍历列表, 打印索引和元素
names = ['Tom', 'Jerry', 'Marry']
for index, name in enumerate(names):
                print('names[{}] = {}'.format(index, name))


打印结果:
names[0] = Tom
names[1] = Jerry
names[2] = Marry

 

posted @ 2017-04-19 13:55  C/C++/Python/Java  阅读(19254)  评论(0编辑  收藏  举报