list.count(obj)
obj -- 這是在列表中要被計數的物件。
#!/usr/bin/python3 aList = [123, 'xyz', 'zara', 'abc', 123]; print ("Count for 123 : ", aList.count(123)) print ("Count for zara : ", aList.count('zara'))
Count for 123 : 2 Count for zara : 1