Python List count()方法
Python List count()方法
count() 方法用于統計某個元素在列表中出現的次數。
語法
count()方法語法:
list.count(obj)
參數
- obj -- 列表中統計的對象。
返回值
返回元素在列表中出現的次數。
實例
以下實例展示了 count()函數的使用方法:
#!/usr/bin/python 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
相關文章
- Python while 循環語句
- Python continue 語句
- Python 元組
- Python IDE
- Python 數據結構
- Python3 環境搭建
- Python3 數字(Number)
- Python3 集合(Set)
- Python3 面向對象
- Python3 多線程
- Python max() 函數
- Python File isatty() 方法
- Python os.dup() 方法
- Python os.fchown() 方法
- Python os.fdatasync() 方法
- Python os.pipe() 方法
- Python swapcase()方法
- Python List len()方法
- Python 字典 Dictionary cmp()方法
- Python 字典 Dictionary copy()方法