for循环

list_test = [1, 3, 6, 2, 5]
for i in list_test:
    print(i)

while循环

list_test = [1, 3, 6, 2, 5]
i = 0
while i < len(list_test):
    print(list_test[i])
    i += 1

enumerate函数

list_test = [1, 3, 6, 2, 5]
for index, value in enumerate(list_test):
    print(index, value)

range函数

list_test = [1, 3, 6, 2, 5]
for i in range(len(list_test)):
    print(i, list_test[i])
# range()函数返回的是一个可迭代对象,不是列表

iter函数

list_test = [1, 3, 6, 2, 5]
for i in iter(list_test):
    print(i)

附:

def test(lst: list):
    # 遍历列表每个元素并统计比其小的元素数量
    j = []
    for i in lst:
        k = 0
        for m in lst:
            if i > m:
                k += 1
        j.append(k)
    return j

Q.E.D.


Nothing really matters to me!