这是用于检查密码长度为9个字符,字母数字且至少包含1个数字的函数的一部分。理想情况下,我应该能够使用第一条if语句,但很奇怪,它不会运行。我无法弄清楚为什么test1.isalpha在if语句中作为'True'运行,但打印为'False'。.isalpha打印为False,但选中时为True
test1 = 'abcd12345'
if len(test1) == 9 and test1.isalnum and not(test1.isalpha)
print('This should work.')
if len(test1) == 9 and test1.isalnum:
if (test1.isalpha):
print('test1 is', test1.isalpha())
>>>('test1 is', False)
在您的一些方法调用之后,您缺少'()'。 – khelwood