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