[issue37490] poor documentation for .startswith, .endswith

Aldwin Pollefeyt report at bugs.python.org
Wed Jul 3 03:30:26 EDT 2019


Aldwin Pollefeyt <aldwinaldwin at gmail.com> 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:
For x in ('day', 'month', 'year'):
    if text[8:12].startswith(x): return True
Else: return False

Maybe indeed could add to the documentation that 'text.startswith(prefix, start, end)' is the same as 'text[start:end].startswith(prefix)'? Although seemed obvious for me.

----------
nosy: +aldwinaldwin

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37490>
_______________________________________


More information about the Python-bugs-list mailing list