在本教程中,我们将看到如何计算清单 在python中
计算列表中的总项目
You can use len()
function to count items in the 清单.
让’借助示例理解。
list1=[1,2,3,4]
print("List:",list1)
length=len(list1)
print("Length of 清单1",length)
输出:
清单1的长度:4
计算列表中每个元素的出现
list1=[1,2,3,4,1,4,3,2,2,1,5]
print("List:",list1)
print("Count of 2 in 清单1:",list1.count(2))
输出:
列表2中的2个计数
那’关于列表中的Python计数项目的所有内容。