[issue37490] poor documentation for .startswith, .endswith

2020-09-19 Thread Irit Katriel
Change by Irit Katriel : -- assignee: -> docs@python components: +Documentation nosy: +docs@python ___ Python tracker ___ ___

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Glenn Linderman
Glenn Linderman added the comment: Thanks for the explanations and suggestions. Now that I think I know what those parameters are used for... Sorry, my first example was tweaked on the fly, and doesn't make as much sense as it could because it wound up being a mix of pre-tweaked and tweaked

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Steven D'Aprano
Steven D'Aprano added the comment: Perhaps it would help if we spelled out the behaviour more explicitly? str.startswith(prefix[, start=0[, end=len(string)]]) Return True if the slice of string between start (defaults to the beginning of the string) and end (defaults to the end of the

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Steven D'Aprano
Steven D'Aprano added the comment: Here are links to the relevant docs: https://docs.python.org/3/library/stdtypes.html#str.startswith https://docs.python.org/3/library/stdtypes.html#str.endswith Both say: "With optional *start*, test string beginning at that position. With optional *end*,

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Aldwin Pollefeyt
Aldwin Pollefeyt added the comment: correction: ... otherwise, text.startswith(prefix, start, end) gives the same result as text[start:end].startswith(prefix). -- ___ Python tracker

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Aldwin Pollefeyt
Aldwin Pollefeyt added the comment: Modified from re module Pattern.search: The optional second parameter 'start' gives an index in the string where the search is to start; it defaults to 0. The optional parameter 'end' limits how far the string will be searched; it will be as if

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Steve Holden
Steve Holden added the comment: "Is the same as" is a little misleading - "gives the same result as" would be better, since there is little doubt actually slicing the subject strings would be massively less efficient in looping contexts. The re module offers the start and end arguments to

[issue37490] poor documentation for .startswith, .endswith

2019-07-03 Thread Aldwin Pollefeyt
Aldwin Pollefeyt added the comment: * text.startswith(prefix, start, end) seems the same as text[start:end].startswith(prefix) * text[start:end] with end>len(text) seems no issue, so also not an issue for startswith * text[8:12] in ('day', 'month', 'year') is not the same at all, rather:

[issue37490] poor documentation for .startswith, .endswith

2019-07-02 Thread Glenn Linderman
Glenn Linderman added the comment: Or is text.startswith(('day', 'month', 'year'), 8, 12) the same as text[8:12] in ('day', 'month', 'year') What happens if the text doesn't have as many as 12 characters? What if it doesn't have more than 8 characters? --

[issue37490] poor documentation for .startswith, .endswith

2019-07-02 Thread Glenn Linderman
New submission from Glenn Linderman : 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"