On 28Apr2014 14:45, taserian <taser...@gmail.com> wrote:
I can't claim to be new to programming, but I've dabbled in Python over and
over again to get small problems and puzzles resolved. One thing that I
find I can't keep straight are the methods that change a list in place, vs.
those that return a copy (sometimes transformed) of the list.

Call me old-fashioned, but my programming experience mostly comes from
languages where you assigned the output of a function to another variable,
so you always had a copy of whatever you were working on.
[...]
Is there some sort of rule-of-thumb to determine if a function is in-place
or returns a value?

In python, the convention is that a function that changes in place returns None. This avois people accidentally thinking they have a copy when in fact they have the original.

Of course, it is a work practice, so you need to consult the doco of any particular function. But it is a good practice to adopt in one's own code.

As you suggest, this keeps the two notions separate by making their use in the code distinct.

Cheers,
Cameron Simpson <c...@zip.com.au>

Too young to rest on the weekend, too old to rest during the week.
        - Mark Randol <ryv...@email.sps.mot.com>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to