By value or by reference?

JCM joshway_without_spam at
Mon Oct 18 22:49:08 CEST 2004

Alex Martelli <aleaxit at> wrote:
> C is also very simple, just like Python: C always does pass by value.
> I.e., C always does implicit copy (on assignment or parameter passing),
> just like Python never does.

> So in C you ask explicitly when you want a reference (pointer) instead,
> e.g. with &foo -- in Python you ask explicitly when you want a copy
> instead, e.g. with copy.copy(foo).  Two simple language, at opposite
> ends of the semantics scale, but each consistent and clean.  (Python
> matches 4.5 of the 5 points which define "the spirit of C" according to
> the latter's Standard's preface...!-).

This is misleading.  copy.copy does a smart, data-structure-aware copy
(not a deep copy, but exactly what copy.copy does differs among
datatypes).  Parameter passing isn't about data structures; it's about
what an assignment statement means when you're assigning to a formal
parameter within a function (also possibly about some other things
like lazy evaluation), for example whether the argument list is a
declaration of new variables or just a set of aliases for other
pre-existing values (I don't say "variables" here because the value
passed in may be anonymous).

More information about the Python-list mailing list