我怎么知道我的代码中的频率(如果语句为 True)?



让我们假设:

for a in range(10):
if a == 2 or a == 5:
print (how often this condition was True) 

当然会是两个,在我的代码中我想知道我的条件什么时候为 True,谢谢

count = 0 # set a variable for counting
for a in range(10): 
if a == 2 or a == 5: # for each entry that meets the condition
count += 1         # add 1 to count
print(count)           # 2

最新更新