# coding:utf-8
# Time:2022/6/28 20:57
# Author:Yang Xiaopeng
num = 23
if num>2:
print("dayu")
if num<2:
print("xiaoyu")
## if else
if num>10:
print("D")
else:
print("A")
## if elif else
if num < 10:
print("D")
elif num < 20:
print("C")
elif num < 30:
print("B")
else:
print("A")
## if nesting
if num > 10:
if num>20:
if num >30:
print("A")
else:
print("B")
else:
print("C")
else:
print("D")
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
2、for loop
# coding:utf-8
# Time:2022/6/28 20:57
# Author:Yang Xiaopeng
for i in (1,2,3,4,5,6,7,8):
if i < 8:
print(i,end="____")
else:
print(i)
list1 = [1,2,3,4,5,6]
for item in list1:
if item / 2 == 1:
print(item)
for item in "asjhlafjhkllsadk":
if item == 'k':
print(item)
else:
print(item,end="_")
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
3、while loop
# coding:utf-8
# Time:2022/6/28 20:57
# Author:Yang Xiaopeng
# Dead cycle
""" while True: pass """
num = 1
while num<10:
print(num,end="_")
num+=1
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
4、break And continue
break: End of cycle
continue Exit this cycle , Continue the next cycle
# coding:utf-8
# Time:2022/6/28 20:57
# Author:Yang Xiaopeng
num = 0
while num<10:
num += 1
if num <=6:
continue
print(num, end="_")
print("")
num =0
while num<10:
num = num + 1
if num == 6:
break
print(num, end="_")