例如,我想计算列表中大于0的数字的数量。我可以在.count()中使用更大,然后更小等的运算符吗?
test_list = ['0','2','3']
for i in test_list:
i = int(i)
larger_zero = test_list.count(i > 0)
print(larger_zero)
Its printing 0
and i wonder why? What is the explanation why its printing a zero?
You could use an iterator with
sum
for that.哪些打印: