String Python dimulai dengan () Metode
Contoh
Periksa apakah string dimulai dengan "Halo":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definisi dan Penggunaan
Metode startswith()
mengembalikan True jika string dimulai dengan nilai yang ditentukan, jika tidak False.
Sintaksis
string.startswith(value, start, end)
Nilai Parameter
Parameter | Description |
---|---|
value | Required. The value to check if the string starts 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 posisi 7 hingga 20 dimulai dengan karakter "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)