CKTIS / Python
str.startswith
Test het exacte begin van de tekst of het gedeelte met optionele start en end, exclusief end.
Versie: Python 3.14; repository image, production runtime not attested
Syntax
s.startswith(prefix[, start[, end]])Test het exacte begin van de tekst of het gedeelte met optionele start en end, exclusief end.
Een tuple staat een van meerdere voorvoegsels toe.
In id:42 beslaat id: de eerste drie posities, dus 42 begint bij index 3.
assert "ab:cd".startswith(("cd", "xy"), 3, 5) and not "ab:cd".startswith("cd", 3, 4)
Voorbeelden
print("id:42".startswith(("id:", "key:")))
print("id:42".startswith("42", 3))
Resultaat
True True
In id:42 beslaat id: de eerste drie posities, dus 42 begint bij index 3.