pythonIf判断
ne = '小新'pw = '123456789'
while True:
name = input('请输入用户名')
password = input('请输入密码')
if name != ne:
print('用户名不正确')
elif password != pw:
print('密码错误')# 新人小白 我有个疑问就是判断正误我只知道两个 == , in,还有哪几个能不能普及一下
else:
print('登录成功')
break 查官方文档最直接{:301_1005:} !=, in , is not 楼主正解,也就是这些了吧? 还有一个 not in == (等于), != (不等于), > (大于), < (小于), >= (大于等于), <= (小于等于)
and (且), or (或), not (非)
is in
elif password != pw:
print('密码错误')
else:
print('登录成功')
#====================
elif password == pw:
print('登录成功')
else:
print('密码错误')
#=====================
elif password is pw: #不建议用is
print('登录成功')
else:
print('密码错误')
#=====================
elif password in pw: #不建议密码判断用in和not in
print('登录成功')
else:
print('密码错误')
#=====================
elif password not in pw:
print('密码错误')
else:
print('登录成功')
MakoStar 发表于 2024-3-18 21:08
查官方文档最直接
官方文档有吗
Chess2l 发表于 2024-3-18 23:18
== (等于), != (不等于), > (大于), < (小于), >= (大于等于),
多谢,我找了老半天 luxingyu329 发表于 2024-3-18 21:30
楼主正解,也就是这些了吧? 还有一个 not in
不应该还有个几个吗我看楼下人的帖子
== (等于), != (不等于), > (大于), < (小于), >= (大于等于), <= (小于等于)
and (且), or (或), not (非)
页:
[1]