पायथन स्ट्रिंग rfind () विधि
उदाहरण
पाठ में स्ट्रिंग "कासा" की अंतिम घटना कहाँ है ?:
txt = "Mi
casa, su casa."
x = txt.rfind("casa")
print(x)
परिभाषा और उपयोग
rfind()
विधि निर्दिष्ट मान की अंतिम घटना का पता लगाती है ।
यदि rfind()
मान नहीं मिलता है तो विधि -1 लौटाती है।
rfind()
विधि लगभग विधि के समान ही
है rindex()
। नीचे उदाहरण देखें।
वाक्य - विन्यास
string.rfind(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 |
और ज्यादा उदाहरण
उदाहरण
पाठ में "ई" अक्षर की अंतिम घटना कहाँ है ?:
txt = "Hello, welcome to my world."
x = txt.rfind("e")
print(x)
उदाहरण
जब आप केवल स्थिति 5 और 10 के बीच खोज करते हैं तो पाठ में "ई" अक्षर की अंतिम घटना कहाँ होती है?:
txt = "Hello, welcome to my world."
x = txt.rfind("e",
5, 10)
print(x)
उदाहरण
यदि मान नहीं मिलता है, तो rfind () विधि -1 लौटाती है, लेकिन rindex () विधि एक अपवाद उत्पन्न करेगी:
txt = "Hello, welcome to my world."
print(txt.rfind("q"))
print(txt.rindex("q"))