Python if条件判断

if else 判断交流

1.判断用户名密码对不对。

 1 import getpass
 2 _username = 'devin'
 3 _password = 'abc123'
 4 username = input("username:")
 5 #password = getpass.getpass("password:")
 6 password = input("password:")
 7 if _username == username and _password == password:
 8   print("Welcome user {name} login...".format(name=username))
 9 else:
10   print("Invalid username or password!")

注:判断语句,print需要\tab不可以与if并列。强制缩进。

if:条件语句

and:并且

or:或者

==:等于

else:如果不成立就执行下面

 

注:判断语句

elif:代表如果不成立或者的意思。

python3默认识别的是字符串,数字需要转换为int数字。

 

posted @ 2017-10-24 16:16  kevin.Xiang  阅读(11033)  评论(0编辑  收藏  举报