python学习之if语句
1.if条件表达式判断
##判断条件是true or false var1=10 if var1: print("true") print(var1) else: print("false") print(var1) var2=0 if var2: print("true") print(var2) else: print("false") print(var2)
输出结果: true 10 false 0
2. 判断输入的字符是否一致
SIZE="hello" char=input("输入字符名称:") if char == SIZE: print("字符名称%s"%char,"等于",SIZE) else: print("请输入字符",SIZE)
输出结果: 输入字符名称:hello 字符名称hello 等于 hello -------------------------- 输入字符名称:world 请输入字符 hello
3.判断登录验证用户名密码
user="desperado pwd="123456" username=input("用户名:") password=input("密码:") if username == user and password == pwd: print("login successful ...") elif username != user: print("the user does not exist") else: print("login fail")