طريقة Python String Count ()
مثال
إرجاع عدد المرات التي تظهر فيها القيمة "تفاحة" في السلسلة:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple")
print(x)
التعريف والاستخدام
تقوم count()
الطريقة بإرجاع عدد المرات التي تظهر فيها قيمة محددة في السلسلة.
بناء الجملة
string.count(value, start, end)
قيمه المعامل
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 |
مزيد من الأمثلة
مثال
ابحث من موقع 10 إلى 24:
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple",
10, 24)
print(x)