This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author v+python
Recipients v+python
Date 2019-07-03.05:01:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562130095.71.0.839529776545.issue37490@roundup.psfhosted.org>
In-reply-to
Content
The documentation is reasonably clear regarding the first parameter, which can be a string or a tuple of strings to match at the start or end of a string.

However, the other two parameters are much less clear in their effect.

text = "Now the day is over"
text.startswith('the', 2, 8)

Does it produce True because 'w the' is at the beginning of the text[2:] ? Maybe. Or because there is an ending position, must it fail because it doesn't match all of text[2:8] ?

text.startswith('day', 8, 10)

Does this produce True because everything in day matches text[8:10] or must it always produce false for any value of text because the match is never as long as the prefix string?

text.startswith(('day', 'month', 'year'), 8, 12)

Can this ever match day or month, because it is comparing to text[8:12], or can only year match because of the start and end?

Is there a difference between the following:

text.startswith(('day', 'month', 'year'), 8, 12)
text[8:12].startswith(('day', 'month', 'year'))

If no difference, why does startswith even need the extra two parameters? Maybe only in performance?

If no difference, why doesn't the documentation describe it that way, so that it could be far clearer?

If there is a difference, what is the difference?

Similar questions for endswith.
History
Date User Action Args
2019-07-03 05:01:35v+pythonsetrecipients: + v+python
2019-07-03 05:01:35v+pythonsetmessageid: <1562130095.71.0.839529776545.issue37490@roundup.psfhosted.org>
2019-07-03 05:01:35v+pythonlinkissue37490 messages
2019-07-03 05:01:35v+pythoncreate