New submission from Glenn Linderman <[email protected]>:
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.
----------
messages: 347179
nosy: v+python
priority: normal
severity: normal
status: open
title: poor documentation for .startswith, .endswith
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37490>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com