Totally Confused: Passing variables to functions

Dan Bishop danb_83 at yahoo.com
Thu Jun 5 20:21:36 EDT 2003


Chuck <cdreward at riaa.com> wrote in message news:<m6ptdvg3p8dvcbpg7qhelb7s2i0slrk7b0 at 4ax.com>...
> I've hit a stumbling block while trying to pick up Python. I've googled
> around, and I don't think I'm the first to have this question, but I haven't
> been able to find an answer that explains things for me.

You said you were familiar with C, so I'll try to explain this using C
code.

> def blah(arg):
>     arg.append(3)

is (roughly) equivalent to

void blah(list *arg) {
   arg->append(3);
}

In general, think of every variable (including function arguments) as
a pointer, and every "." as a "->".

> But it's not [pass-by-reference], because if I say "arg = None" inside the
> function, "v" is unchanged.

void blah(list *arg) {
   arg = NULL;
}

All Python assignment statements have the semantics of C's "lhs=rhs;"
and NOT "*lhs=*rhs;".




More information about the Python-list mailing list