Python-String -startswith()- Methode
Beispiel
Überprüfen Sie, ob die Zeichenfolge mit "Hello" beginnt:
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definition und Verwendung
Die startswith()
Methode gibt True zurück, wenn der String mit dem angegebenen Wert beginnt, andernfalls False.
Syntax
string.startswith(value, start, end)
Parameterwerte
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 |
Mehr Beispiele
Beispiel
Prüfen Sie, ob die Positionen 7 bis 20 mit den Zeichen "wel" beginnen:
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)