You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中为何‘and not’逻辑无法实现密码需大写和数字的校验?

Why Your "and not" Logic Isn't Triggering Correctly

Hey there! Let's walk through exactly why your current condition isn't catching the cases where the password has a capital letter but no number, or a number but no capital letter.

First, let's look at your conditional line again:

if password.islower() and "1234567890" not in password:

Let's break down each part of this condition and how they interact:

  • password.islower(): This checks if every single character in the password is lowercase. If there's even one uppercase letter present, this returns False right away.
  • "1234567890" not in password: This checks if the password contains no digits at all. If any digit exists in the password, this returns False.

Now let's map this to your problematic scenarios:

  1. Password has a capital letter but no number:
    • password.islower() becomes False (thanks to the uppercase letter), so the entire and condition fails (since and requires both parts to be True). That's why the error message doesn't show up here.
  2. Password has a number but no capital letter:
    • password.islower() is True (all characters are lowercase), but "1234567890" not in password becomes False (since there's a digit). Again, the and condition needs both parts to be True to trigger, so the error message stays hidden.

Only when both the password is entirely lowercase and has no digits does the condition evaluate to True—which is why that's the only case your error message appears.

内容的提问来源于stack exchange,提问作者Anderdoodle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 13:47:45