The difference between pass, continue and break in python3

# continue will not execute the statement after this loop (print(i))
# pass is a placeholder and will continue to execute the statement in the loop
# break exit the loop directly

list = [21, 6, 9, 8, 13, 5, 4]

def minlist(list):
    ml = list[0]
    for i in list:
        if ml > i:
            ml = i
        else:
            continue
        print(i)
    return ml

print(minlist(list))

# 输出为:
# 6
# 5
# 4
# 4

list = [21, 6, 9, 8, 13, 5, 4]

def minlist(list):
    ml = list[0]
    for i in list:
        if ml > i:
            ml = i
        else:
            pass
        print(i)
    return ml

print(minlist(list))

# 输出为:
21
6
9
8
13
5
4
4
list = [21, 6, 9, 8, 13, 5, 4]

def minlist(list):
    ml = list[0]
    for i in list:
        if ml > i:
            ml = i
        else:
            break
        print(i)
    return ml

print(minlist(list))

# 输出为
21

おすすめ

転載: blog.csdn.net/zhangliang0000/article/details/122791809