Scope of python variable in for loop

前端 未结 10 1865
一整个雨季
一整个雨季 2020-11-22 15:16

Heres the python code im having problems with:

for i in range (0,10):
    if i==5:
        i+=3
    print i

I expected the output to be:

10条回答
  •  花落未央
    2020-11-22 15:53

    You can make the following modification to your for loop:

    for i in range (0,10):
        if i in [5, 6, 7]:
            continue
        print(i)
    

提交回复
热议问题