[Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

Cameron Simpson cs at zip.com.au
Sat Jan 16 21:02:32 EST 2016


On 16Jan2016 18:43, boB Stepp <robertvstepp at gmail.com> wrote:
>This led me to try:
>
>>>> mylist[:None]
>[100, 200, 300, 400, 500]
>
>So, in effect, None is acting as a place holder for that final
>position in slices.  Also, I would never have thought to be able to
>use a logical "or" inside an index in Peter's "[:-i or None]".

Yah, like the default value for many missing parameters. When you don't need an 
expression after the ":" you can of course write:

  mylist[:]

much like writing a function "def f(x, y=None)"; None is a sentinel value - 
specially recognised as nor in the normal domain for that value.

Cheers,
Cameron Simpson <cs at zip.com.au>

Q: How does a hacker fix a function which doesn't work for all of the elements 
in its domain?
A: He changes the domain.
- Rich Wareham <rjw57 at hermes.cam.ac.uk>



More information about the Tutor mailing list