Python String count() နည်းလမ်း
ဥပမာ
စာကြောင်းတွင် "apple" တန်ဖိုးပေါ်လာသည့်အကြိမ်အရေအတွက်ကို ပြန်ပေးပါ။
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple")
print(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် count()
string တွင်သတ်မှတ်ထားသောတန်ဖိုးတစ်ခုပေါ်လာသည့်အကြိမ်အရေအတွက်ကိုပြန်ပေးသည်။
အထားအသို
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 |
နောက်ထပ် ဥပမာများ
ဥပမာ
အနေအထား ၁၀ မှ ၂၄ အထိ ရှာဖွေရန်။
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple",
10, 24)
print(x)