Metoda Python String beginwith()
Příklad
Zkontrolujte, zda řetězec začíná „Ahoj“:
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
Definice a použití
Metoda startswith()
vrátí True, pokud řetězec začíná zadanou hodnotou, jinak False.
Syntax
string.startswith(value, start, end)
Hodnoty parametrů
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 |
Další příklady
Příklad
Zkontrolujte, zda pozice 7 až 20 začíná znaky „wel“:
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)