Application Scene
顺序结构: 一条 一条语句顺序执行。(顺序结构不能解决所有场景问题)
分支结构(选择结构): 两个分支,其中只能有一个分支会被执行。
if语句的使用
Python中,分支结构使用的关键字(拥有特殊意义的单词)是if、elif、else.
if, else 是专门用于构造结构的关键字。
"""
用户身份验证
Version: 0.1
Author: Maxwell
"""
username = input('please input username: ')
password = input('please input password: ')
# username : admin and password: 123456 to verify
if username == 'admin' and password == '123456':
print('Verification sucessful')
else:
print('Verification failed')
需要说明的是和C/C++、Java等语言不同,Python中没有用花括号来构造代码块而是使用了缩进的方式来表示代码的层次结构,如果if
条件成立的情况下需要执行多条