Python Forum
str.endswith(): vague documentation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: str.endswith(): vague documentation (/thread-22619.html)



str.endswith(): vague documentation - Skaperen - Nov-20-2019

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?


RE: str.endswith(): vague documentation - Gribouillis - Nov-20-2019

>>> 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.


RE: str.endswith(): vague documentation - Skaperen - Nov-21-2019

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)?


RE: str.endswith(): vague documentation - LeanbridgeTech - Nov-22-2019

The endswith() method returns True if a string ends with the given suffix otherwise returns False.

Syntax :

str.endswith(suffix, start, end)


RE: str.endswith(): vague documentation - Skaperen - Nov-22-2019

(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?