Python Dize sayısı() Yöntem
Örnek
Dizede "elma" değerinin kaç kez göründüğünü döndürün:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple")
print(x)
Tanım ve Kullanım
Yöntem count()
, dizede belirtilen bir değerin kaç kez göründüğünü döndürür.
Sözdizimi
string.count(value, start, end)
Parametre Değerleri
Parameter | Description |
---|---|
value | Required. A String. The string to value to search for |
start | Optional. An Integer. The position to start the search. Default is 0 |
end | Optional. An Integer. The position to end the search. Default is the end of the string |
Daha fazla örnek
Örnek
10'dan 24'e kadar arama yapın:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple",
10, 24)
print(x)