python面试题:pass vs break vs continue

pass: do nothing to this loop

number = [1,2,3]
for i in number:
if i==2:
pass
print(i)
D:\python\python.exe D:\pycharm\joy_test_repo\test\test.py
1
2
3

continue terminal this loop, continue next loop

number = [1,2,3]
for i in number:
if i==2:
continue
print(i)
D:\python\python.exe D:\pycharm\joy_test_repo\test\test.py
1
3

Process finished with exit code 0

break, terminal whole loop

number = [1,2,3]
for i in number:
if i==2:
break
print(i)
D:\python\python.exe D:\pycharm\joy_test_repo\test\test.py
1

Process finished with exit code 0

你可能感兴趣的:(python,开发语言)