python 遍历

lst = [0,1,2,3,4]
for x in lst:
    print x 
# output : 0 1 2 3 4 

for x in xrange (0, len(str)):
    print lst[x]
# output : 0 1 2 3 4
for x in xrange(0, len(str), 2):
    print lst[x]
# output : 0 2 4


for x in xrange(len(lst) - 1, -1, -1):
    print lst[x]
# 4 3 2 1 0
for x in lst[::-1]
    print x
# 4 3 2 1 0

shiyang6017
158 声望59 粉丝