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.

    var array;
    sorted = array.sort();

If you didn't care to keep both copies, you could always re-assign the
returned value to the original variable.

    array = array.sort();

If I try to do the same in Python:

    sorted = arrayList.sort()

sorted comes back as None, while arrayList has changed its order.

Is there some sort of rule-of-thumb to determine if a function is in-place
or returns a value?

Antonio Rodriguez
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to