【问题标题】:Looking For Things in Lists, In Inputs在列表、输入中寻找东西
【发布时间】:2018-06-25 13:41:12
【问题描述】:

我目前正在 Python 3.3.2 上制作密码检查器,我目前正在通过执行以下操作在用户输入中查找内容:

if ("A" in PassCheck) or ("B" in PassCheck) or ("C" in PassCheck) or ("D")in 
PassCheck) or ("E" in PassCheck) or ("F" in PassCheck) or ("G" in PassCheck) 
or ("H" in PassCheck) or ("I" in PassCheck) or ("J" in PassCheck) or ("K" in 
PassCheck) or ("L" in PassCheck) or ("M" in PassCheck) or ("N" in PassCheck 
 or
("O" in PassCheck) or ("P" in PassCheck) or ("Q" in PassCheck) or ("R" in 
PassCheck) or ("S" in PassCheck) or ("T" in PassCheck) or ("U" in PassCheck)
or ("V" in PassCheck) or ("W" in PassCheck) or ("X" in PassCheck) or ("Y" in 
PassCheck) or ("Z" in PassCheck):

有没有办法通过列表来做到这一点?

【问题讨论】:

标签: python list input


【解决方案1】:

您可以使用string 库通过string.ascii_uppercase 模块搜索是否存在大写字符

>>> import string
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

然后您可以使用any 函数来测试给定字符串输入是否存在大写字符。

>>> Pass_Check_1 = 'ThisOneWorks'
>>> any(i in Pass_Check_1 for i in string.ascii_uppercase)
True

>>> Pass_Check_2 = 'thisonedoesntwork'
>>> any(i in Pass_Check_2 for i in string.ascii_uppercase)
False

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2019-07-24
    • 1970-01-01
    • 2021-03-02
    • 2021-09-23
    • 2012-06-10
    相关资源
    最近更新 更多