Steven D'Aprano wrote:
> def modify_in_place(obj):
>     """Modify an arbitrary object in place."""
>     obj = None
>
> x = [1, 2, 3] # mutable object
> modify_in_place(x)
> assert x is None
>
>
> Doesn't work either.

To be fair, this isn't because the function is not pass by reference,
but because the assignment operator reassigns the reference rather than
altering the referent, and thus modify_in_place doesn't actually
contain any modifying operations. With a good understanding of what
Python's assignment operator actually does, (I believe) you can view
Python as pass-by-reference without any semantic problems.

-- 
Ben Sizer

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to