Getting started with Python 2

Getting started with Python 2

For and Else

1
2
3
4
for x in range(6):
print(x)
if x==2: break
else: print("over") # this line will skip if last line exists

Pass

There cannot exist any blank within for and if else. We must use pass to avoid the mistake.

1
2
3
for x in [1,2,3,4]:
pass
print("over")
Author

Haojin Li

Posted on

01-31-2020

Updated on

03-05-2022

Licensed under

Comments