在Python中,我们有3种循环控制语句:break、continue和pass。
当条件满足时,循环中断并跳出循环。
for i in range(10): print(i) if i == 5: break # It will print : 0 to 5 and once the condition satisfies, # then the loop breaks.
当条件满足时,将跳过并进入循环中的下一次迭代。
for i in range(10): if i == 5: continue print(i) # It will print : 0 to 9 except 5.
for i in range(10): if i != 5 : continue print(i) # It will print just 5.
它什么也没做。它充当占位符。
for i in range(10): if i == 5: pass print(i) # It will not do anything, even if the condition satisfies
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3