日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythoncount()

python 中的count()函數(shù)有助于返回元組中給定元素的出現(xiàn)次數(shù)。元組是一種內(nèi)置的數(shù)據(jù)類型,用于存儲多個元素,它是有序且不可更改的。

 **tuple.count(element)** #where element may be a integer,string,etc. 

計數(shù)()參數(shù):

count()函數(shù)接受一個參數(shù)。如果參數(shù)丟失,它將返回一個錯誤。

參數(shù) 描述 必需/可選
元素要計數(shù)的元素需要

計數(shù)()返回值

返回值始終是一個整數(shù),它指示特定元素在元組中出現(xiàn)的次數(shù)。如果元組中沒有給定的元素,它將返回零。

| 投入 | 返回值 | | 元素 | 整數(shù)(計數(shù)) |

Python 中count()方法的示例

示例 1:元組計數(shù)()在皮托中是如何工作的?

 # vowels tuple
alphabets = ('a', 'b', 'c', 'd', 'a', 'b')

# count element 'a'
count = alphabets .count('a')

# print count
print('The count of a is:', count)

# count element 'c'
count = alphabets .count('c')

# print count
print('The count of c is:', count) 

輸出:

 The count of a is: 2
The count of c is: 1 

示例 2:如何統(tǒng)計 tuple 中的列表和 Tuple 元素?

 # random tuple
random_tup = ('a', ('b', 'c'), ('b', 'c'), [1, 2])

# count element ('b', 'c')
count = random_tup.count(('b', 'c'))

# print count
print("The count of ('b', 'c') is:", count)

# count element [1, 2]
count = random_tup.count([1, 2])

# print count
print("The count of [1, 2] is:", count) 

輸出:

 The count of ('b', 'c') is: 2
The count of [1, 2] is: 1 

文章名稱:創(chuàng)新互聯(lián)Python教程:Pythoncount()
URL分享:http://www.dlmjj.cn/article/cdghcsc.html