[Tutor] Python vs. MATLAB

Wayne Werner waynejwerner at gmail.com
Mon Dec 6 18:53:45 CET 2010

On Mon, Dec 6, 2010 at 11:09 AM, Joel Schwartz <joel at joelschwartz.com>wrote:

> Chris,
> Can you say more about number (7) in your list? What does "pass by value"
> mean and what are the alternatives?

Pass by value is exactly what it sounds like - you pass the value (a copy of
everything in the memory). This is bad when you're passing a 10,000 item
list to a function - because you now have *two* 10,000 item lists. It's even
worse when you have many times that amount of data.

Python, OTOH passes by reference - instead of copying the list, a pointer to
the list is passed, so when you see something like this:

def do_something(a_list):
    a_list[2] = 4

mylist = [1,2,3,4]

now mylist is:


This is much more efficient (although it tends to bite novice programmers!).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101206/68259841/attachment.html>

More information about the Tutor mailing list