新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中count函數(shù)是什么意思?
python中,count函數(shù)的作用是進行python中的數(shù)量計算。count函數(shù)用于統(tǒng)計字符串、列表或元祖中某個字符出現(xiàn)的次數(shù),是一個很好用的統(tǒng)計函數(shù)。具體介紹請看本文。

1、count函數(shù)
統(tǒng)計列表ls中value元素出現(xiàn)的次數(shù)
2、語法
str.count("char", start,end)或
str.count("char") -> int 返回整數(shù)3、參數(shù)
str —— 為要統(tǒng)計的字符(可以是單字符,也可以是多字符)。
star —— 為索引字符串的起始位置,默認參數(shù)為0。
end —— 為索引字符串的結(jié)束位置,默認參數(shù)為字符串長度即len(str)。
4、返回值
返回統(tǒng)計參數(shù)出現(xiàn)的次數(shù)
5、實例:
list 中 某元素 的次數(shù)
list = [10, 20, 30, 'Hello', 10, 20]
print "list.count('Hello') : ", list.count('Hello')
print "list.count(10) : ", list.count(10)輸出
list.count('Hello') : 1
list.count(10) : 2以上就是python中count函數(shù)的介紹,count函數(shù)的使用很容易操作,可以便于我們統(tǒng)計數(shù)量,大家可以嘗試看看哦~
網(wǎng)站名稱:創(chuàng)新互聯(lián)Python教程:python中count函數(shù)是什么意思?
URL鏈接:http://www.dlmjj.cn/article/dhegjdi.html


咨詢
建站咨詢
