Python String rindex() နည်းလမ်း
ဥပမာ
စာသားတွင် မည်သည့်နေရာတွင် "casa" ၏ နောက်ဆုံး ဖြစ်ပေါ်မှုဖြစ်သနည်း။
txt = "Mi
casa, su casa."
x = txt.rindex("casa")
print(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
rindex()
နည်းလမ်းသည် သတ်မှတ်ထားသောတန်ဖိုး၏ နောက်ဆုံးဖြစ်ပေါ်မှုကို ရှာဖွေသည် ။
တန်ဖိုးကို ရှာမတွေ့ပါ က rindex()
နည်းလမ်းသည် ခြွင်းချက်တစ်ခုဖြစ်သည်။
နည်းလမ်း သည် rindex()
နည်းလမ်းနှင့်နီးပါးတူ
rfind()
ပါသည်။ အောက်ပါဥပမာကိုကြည့်ပါ။
အထားအသို
string.rindex(value, start, end)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
value | Required. The value to search for |
start | Optional. Where to start the search. Default is 0 |
end | Optional. Where to end the search. Default is to the end of the string |
နောက်ထပ် ဥပမာများ
ဥပမာ
စာသားတွင် စာလုံး "e" ၏ နောက်ဆုံးဖြစ်ပျက်မှုသည် အဘယ်မှာရှိသနည်း။
txt = "Hello, welcome to my world."
x = txt.rindex("e")
print(x)
ဥပမာ
ရာထူး 5 နှင့် 10 ကြားတွင်သာ သင်ရှာဖွေသောအခါတွင် စာလုံး "e" ၏ နောက်ဆုံးဖြစ်ပျက်မှုမှာ စာသား၌ အဘယ်မှာရှိသနည်း။
txt = "Hello, welcome to my world."
x = txt.rindex("e",
5, 10)
print(x)
ဥပမာ
တန်ဖိုးကို ရှာမတွေ့ပါက၊ rfind() method သည် -1 ကို ပြန်ပေးသည်၊ သို့သော် rindex() method သည် ခြွင်းချက်တစ်ခု တိုးလာလိမ့်မည်-
txt = "Hello, welcome to my world."
print(txt.rfind("q"))
print(txt.rindex("q"))