String Python diakhiri dengan () Metode
Contoh
Periksa apakah string diakhiri dengan tanda baca (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definisi dan Penggunaan
Metode endswith()
mengembalikan True jika string diakhiri dengan nilai yang ditentukan, jika tidak False.
Sintaksis
string.endswith(value, start, end)
Nilai Parameter
Parameter | Description |
---|---|
value | Required. The value to check if the string ends with |
start | Optional. An Integer specifying at which position to start the search |
end | Optional. An Integer specifying at which position to end the search |
Lebih Banyak Contoh
Contoh
Periksa apakah string diakhiri dengan frasa "duniaku.":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Contoh
Periksa apakah posisi 5 hingga 11 berakhir dengan frasa "duniaku.":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)