Methode Python String startswith()
Voorbeeld
Controleer of de string begint met "Hallo":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definitie en gebruik
De startswith()
methode retourneert True als de tekenreeks begint met de opgegeven waarde, anders False.
Syntaxis
string.startswith(value, start, end)
Parameterwaarden
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 |
Meer voorbeelden
Voorbeeld
Controleer of positie 7 t/m 20 begint met de karakters "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)