Python Dizisi bul() Yöntemi
Örnek
Metnin neresinde "hoş geldiniz" kelimesi var?:
txt = "Hello, welcome to my world."
x = txt.find("welcome")
print(x)
Tanım ve Kullanım
Yöntem find()
, belirtilen değerin ilk oluşumunu bulur.
Değer find()
bulunamazsa yöntem -1 döndürür.
Yöntem find()
, yöntem ile hemen hemen aynıdır
index()
, tek fark, index()
değer bulunamazsa yöntemin bir istisna oluşturmasıdır. (Aşağıdaki örneğe bakın)
Sözdizimi
string.find(value, start, end)
Parametre Değerleri
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 |
Daha fazla örnek
Örnek
Metinde "e" harfinin ilk geçtiği yer neresidir?:
txt = "Hello, welcome to my world."
x = txt.find("e")
print(x)
Örnek
Yalnızca 5 ve 10. konumlar arasında arama yaptığınızda, metinde "e" harfinin ilk geçtiği yer neresidir?:
txt = "Hello, welcome to my world."
x = txt.find("e",
5, 10)
print(x)
Örnek
Değer bulunamazsa, find() yöntemi -1 değerini döndürür, ancak index() yöntemi bir istisna oluşturur:
txt = "Hello, welcome to my world."
print(txt.find("q"))
print(txt.index("q"))