Python Forum

Full Version: str.endswith(): vague documentation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
reading up on str.endswith() i find the optional arguments start and end to be described vaguely. it does not say how they apply, like whether they affect both strings at the same time or just one of them. and if they apply to the string in argument 1, does the end of its substring always get checked as if it was located with end at the end?
>>> s = 'spam ham eggs'
>>> s.endswith('ham', None, 8)
True
>>> s.endswith('ham', 3, 8)
True
I would guess that s.endswith(x, start, stop) gives the same result as s[start:stop].endswith(x) but it saves the creation of a str instance.
that was one of the guesses i had. but the documentation does not give enough clue to pin that down or confirm it. is saving the creation of a string instance considered important in a system where performance considerations are generally limited (to use the correct algorithm)?
The endswith() method returns True if a string ends with the given suffix otherwise returns False.

Syntax :

str.endswith(suffix, start, end)
(Nov-22-2019, 05:29 AM)LeanbridgeTech Wrote: [ -> ]The endswith() method returns True if a string ends with the given suffix otherwise returns False.

Syntax :

str.endswith(suffix, start, end)

even if start and end have random int values in those argument positions?