If I want to use only the index within a loop, should I better use the range/xrange
function in combination with len()
a = [1,2,3]
for i in xrange(len(a)):
print i
or enumerate
? Even if I won't use p
at all?
for i,p in enumerate(a):
print i
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…