Python String eindigt met () Methode
Voorbeeld
Controleer of de string eindigt met een leesteken (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
Definitie en gebruik
De endswith()
methode retourneert True als de tekenreeks eindigt met de opgegeven waarde, anders False.
Syntaxis
string.endswith(value, start, end)
Parameterwaarden
Parameter | Description |
---|---|
value | Required. The value to check if the string ends 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 de string eindigt met de zin "mijn wereld.":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
Voorbeeld
Controleer of positie 5 t/m 11 eindigt met de zin "mijn wereld.":
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)