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