Count () yöntemi, belirtilen öğenin tuple'da kaç kez göründüğünü döndürür.
count()
Yöntemin sözdizimi şöyledir:
tuple.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, demet içinde katı eleman göründüğünü sayısını verir.
Örnek 1: Tuple count () kullanımı
# vowels tuple 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: Tuple İçinde Liste ve Tuple Öğelerini Say
# random tuple 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