names = [‘old_driver‘, ‘rain‘, [‘oldboy‘, ‘oldgirl‘], ‘jack‘, ‘珊珊‘, ‘peiqi‘, ‘Alex‘, ‘black_girl‘, 1, 2, 3, 4, 2, 5, 6, 2] for i,k in enumerate(names): #枚举可以快捷的打印出索引和对应的元素 print(i, k)
count = 0
names = [‘old_driver‘, ‘rain‘, [‘oldboy‘, ‘oldgirl‘], ‘jack‘, ‘珊珊‘, ‘peiqi‘, ‘Alex‘, ‘black_girl‘, 1, 2, 3, 4, 2, 5, 6, 2]
for i in names: print(count,i) count += 1 #用计数法也可以打印索引和对应的元素
原文地址:https://www.cnblogs.com/yuexijun/p/9932460.html
时间: 2024-10-21 01:30:19