Python的分支,循环与条件

了解条件,循环语句~

什么是表达式

表达式(Expression)就是运算符(operator)和操作数(operand)所构成的序列

表达式的优先级

请自行百度~ 贴图太多网页卡

常用的Python开发软件

vscode sublime pycharm

条件控制语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
""" 
一段小程序
"""

account = 'liupeng'
password = '123456'

print('please input account')
user_account = input()
print('please input password')
user_password = input()

if (user_account == account) and (password == user_password):
print('验证通过~')
else:
print('验证失败~')

if True:
pass # pass 占位符
elif:
pass
else:
pass

循环语句

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
con = 0
# 适用于递归
while con <= 10 :
con += 1
print(con)
else:
print('nb~')

# 主要是用来遍历/循环 序列或者集合,字典
x = [[1,2,3,4],('a','b','c')]
for a in x:
for b in a:
if b == 2:
# continue
break
print(b)
else:
print('结束~')

# for(i=1; i<10; i++){}
# range() 起始,结束,步长
for a in range(0,10,2):
print(a,end=' | ')

for a in range(10,0,-2):
print(a,end=' | ')