range() and slice semantics
Jay Bloodworth <[email protected]> Mon, 26 Aug 2019 13:06:12 -0400
| Newsgroups | gmane.comp.python.education |
|---|---|
| Message-ID | <[email protected]> |
Does anybody have a nice, student friendly explanation of the "half-open" semantics of the range function and of slice notation? In other words, why does the list created by range(0,10) contain 0 as an element but not 10, and why does mylist[0:10] start with mylist[0] and end with mylist[9]? If you're an experienced coder, these semantics make sense in terms of the underlying implementation and the usual use of these objects as iterators, but if lists are new to you the behavior can seem a little mysterious. Thoughts? Jay