日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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. 

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

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

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

計(jì)數(shù)()返回值

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

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

Python 中count()方法的示例

示例 1:元組計(jì)數(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)計(jì) 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 

網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:Pythoncount()
標(biāo)題路徑:http://m.5511xx.com/article/cdghcsc.html