Endswith () yöntemi, bir dize belirtilen sonekle biterse True döndürür. Değilse, False döndürür.
Sözdizimi endswith()
şöyledir:
str.endswith (sonek (, başlangıç (, bitiş)))
endswith () Parametreler
endswith()
Üç parametre alır:
- sonek - Kontrol edilecek son eklerin dizesi veya demeti
- start (isteğe bağlı) - Dizide son ekin kontrol edileceği başlangıç konumu .
- end (isteğe bağlı) - Son ekin dize içinde kontrol edileceği bitiş konumu .
Endswith () 'den Dönüş Değeri
endswith()
Yöntem, bir boolean döndürür.
- Dizeler belirtilen sonekle biterse True döndürür.
- Dize belirtilen sonek ile bitmezse False döndürür.
Örnek 1: endswith () Başlangıç ve bitiş parametreleri olmadan
text = "Python is easy to learn." result = text.endswith('to learn') # returns False print(result) result = text.endswith('to learn.') # returns True print(result) result = text.endswith('Python is easy to learn.') # returns True print(result)
Çıktı
Yanlış Doğru Doğru
Örnek 2: endswith () Başlangıç ve bitiş Parametreleri ile
text = "Python programming is easy to learn." # start parameter: 7 # "programming is easy to learn." string is searched result = text.endswith('learn.', 7) print(result) # Both start and end is provided # start: 7, end: 26 # "programming is easy" string is searched result = text.endswith('is', 7, 26) # Returns False print(result) result = text.endswith('easy', 7, 26) # returns True print(result)
Çıktı
Doğru Yanlış Doğru
Tuple'ı endswith () 'e aktarma
endswith()
Python'da yönteme bir demet son eki aktarmak mümkündür .
Dize, başlığın herhangi bir öğesiyle biterse, endswith()
True döndürür. Değilse, False döndürür
Örnek 3: başlık Soneki ile endswith ()
text = "programming is easy" result = text.endswith(('programming', 'python')) # prints False print(result) result = text.endswith(('python', 'easy', 'java')) #prints True print(result) # With start and end parameter # 'programming is' string is checked result = text.endswith(('is', 'an'), 0, 14) # prints True print(result)
Çıktı
Yanlış Doğru Doğru
Bir dizenin belirtilen önek ile başlayıp başlamadığını kontrol etmeniz gerekiyorsa, Python'da startswith () yöntemini kullanabilirsiniz.