Python Listesi sayısı ()

Count () yöntemi, belirtilen öğenin listede görünme sayısını döndürür.

count()Yöntemin sözdizimi şöyledir:

 list.count (öğe)

count () Parametreler

count()Yöntem, tek bir argüman alır:

  • öğe - sayılacak öğe

Count () değerinden dönüş değeri

count()Yöntem listesindeki kez eleman göründüğünü sayısını döndürür.

Örnek 1: count () kullanımı

 # vowels list vowels = ('a', 'e', 'i', 'o', 'i', 'u') # count element 'i' count = vowels.count('i') # print count print('The count of i is:', count) # count element 'p' count = vowels.count('p') # print count print('The count of p is:', count) 

Çıktı

 İ'nin sayısı: 2 p'nin sayısı: 0

Örnek 2: Demeti Sayma ve Listedeki Öğeleri Listeleme

 # random list random = ('a', ('a', 'b'), ('a', 'b'), (3, 4)) # count element ('a', 'b') count = random.count(('a', 'b')) # print count print("The count of ('a', 'b') is:", count) # count element (3, 4) count = random.count((3, 4)) # print count print("The count of (3, 4) is:", count)  

Çıktı

 ('A', 'b') sayısı: 2 (3, 4) 'ün sayısı: 1

Ilginç makaleler...