Baza znanjaIzpitno središče
SLSlovenščina
Izberi jezik13

CKTIS / Python

str.startswith

Preveri natančen začetek besedila ali dela z neobveznima start in end, brez položaja end.

Različica: Python 3.14; repository image, production runtime not attested

Sintaksa

s.startswith(prefix[, start[, end]])

Preveri natančen začetek besedila ali dela z neobveznima start in end, brez položaja end.

Terka dopusti katero koli od več predpon.

V id:42 zavzame id: prve tri položaje, zato se 42 začne pri indeksu 3.

assert "ab:cd".startswith(("cd", "xy"), 3, 5) and not "ab:cd".startswith("cd", 3, 4)

Primeri

print("id:42".startswith(("id:", "key:")))
print("id:42".startswith("42", 3))

Rezultat

True
True

V id:42 zavzame id: prve tri položaje, zato se 42 začne pri indeksu 3.

Viri