How to do * and & C-lang. operations in Python?

Chris Barker chrishbarker at home.net
Fri Sep 21 15:09:12 EDT 2001


Toni Gaya wrote:

> Assignaments are done by 'value', not by 'reference'. Function calls
> are done by 'reference'. How to do assignaments by reference?. In C
> language, I can do:

I hadn't read Guido's tutorial ( http://www.python.org/doc/current/tut/
)for a long time, but I just looked at it, and saw this pasage, which is
relevant to your question::

"""
Objects have individuality, and multiple names (in multiple scopes) can
be bound to the same object. This is known as aliasing in other
languages. This is usually not
appreciated on a first glance at Python, and can be safely ignored when
dealing with immutable basic types (numbers, strings, tuples). However,
aliasing has an
(intended!) effect on the semantics of Python code involving mutable
objects such as lists, dictionaries, and most types representing
entities outside the program
(files, windows, etc.). This is usually used to the benefit of the
program, since aliases behave like pointers in some respects. For
example, passing an object is cheap since only a pointer is passed by
the implementation; and if a function modifies an object passed as an
argument, the caller will see the change -- this obviates the need for
two different argument passing mechanisms as in Pascal. 
"""

-Chris



-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list