Python 如何检查if语句列表中的字符串值?

Python 如何检查if语句列表中的字符串值?,python,Python,我有以下代码: s = ['01','06','11','16','21','26','31','36','41','46','51','56'] while True: for a in s: if time.strftime('%S') == a: print 'YES' else: print time.strftime('%S') time.slee

我有以下代码:

s = ['01','06','11','16','21','26','31','36','41','46','51','56']

while True:
    for a in s:
        if time.strftime('%S') == a:             
            print 'YES'
        else:
            print time.strftime('%S')
            time.sleep(1)
            print a
但它不起作用

有什么办法让它工作吗?

在这种情况下,每次
%S
获取
S
中的一些值时,它都会打印
'YES'
,您需要在每个循环中调用
sleep
,并在匹配列表中查找当前秒数:

>>> import time
>>>
>>> matches = ['01','06','11','16','21','26','31','36','41','46','51','56']
>>>
>>> while True:
...     seconds = time.strftime('%S')
...     if seconds in matches:
...         print('YES')
...     else:
...         print(seconds)
...     time.sleep(1)
...
07
08
09
10
YES
12
13
14
15
YES
17
18
19

为什么操作系统不工作?有错误吗?你的计划到底应该做什么?我同意Rik的观点。你应该养成习惯,在你的问题中加入回溯。