Small problem

The list or user-uploaded tuples returned by the index corresponding to the odd elements of the user

def qishu(l):
    d = []
    for index in range(len(l)):
         if index % 2 ==1:
            d.append(l[index])
         else:
             pass
    print(d)

qishu([123,5,345,234,435,546,234,3])
View Code
def qishu(l):
    print(l[1::2])
    return l
qishu((21,34,56,2,3243,5435,465,73,435,43))
View Code

Two methods, one loop for a slice,

Although small slice start code, but can only play a limited scope, once the demand complicated, it can not meet the

Guess you like

Origin www.cnblogs.com/zly9527/p/11286021.html