流程控制语句
一、if else条件控制语句
必须要有四个缩进,否则不会被视为是if或else的部分(用四个缩进代替C语言的{})
mood = False
if mood :
print('go to left')
else :
print('go to right')
一段小程序:
ACCOUNT = 'cly'
PASSWORD = '123456'
print('请输入账号名')
user_account = input()
print('请输入密码')
user_password = input()
if user_account == ACCOUNT and user_password == PASSWORD:
print('登录成功')
else:
print('请重新登录')
snippet:好用,不过要下个插件(python snippet)
嵌套,以及用函数代替嵌套中的表达式
if True:
pass #pass空语句/占位
if False:
pass
#嵌套
if condition:
code1
code11
code111
code2
else:
code1