Re: Passing arguments to function - (The fundamentals are confusing me)
- From: Rocco Moretti <roccomoretti@xxxxxxxxxx>
- Date: Tue, 09 Aug 2005 12:12:26 -0500
Gregory Piñero wrote:
Ahh, so it's a mutable thing. That makes sense that I can't change a
mutable object and thus can't affect it outside of the function.
If you meant "immutable" for the second mutable, you're right.
Does that mean Python functions aren't always byref, but are sometimes byval for nonmutables?
It'd probably do you good to get away from the by reference/by value thinking. Python isn't C/Basic/Fortran/etc.
Variables in Python are names. They aren't the cubbyholes into which you put values, they are sticky notes on the front of the cubby hole.
Parameter passing in Python always work the same way - you create a new name pointing to the passed object. Fin.
The confusion you're having isn't in parameter passing, it's in the difference between assignment and mutation. Mutation changes the object itself (what's in the cubby hole), so it doesn't matter what or how many names/variables it has (what sticky notes are on the front). Assigment just changes where names point, not the contents of objects. (It's moving that sticky note, and only that sticky note, from one cubby to a different one.) Assignment justs affects that name, not any other name which point to the same object, including the variables in the passing scope.
.
- Follow-Ups:
- Re: Passing arguments to function - (The fundamentals are confusing me)
- From: Christopher Subich
- Re: Passing arguments to function - (The fundamentals are confusing me)
- References:
- Passing arguments to function - (The fundamentals are confusing me)
- From: Gregory Piñero
- Re: Passing arguments to function - (The fundamentals are confusing me)
- From: Gregory Piñero
- Passing arguments to function - (The fundamentals are confusing me)
- Prev by Date: Examples and tutorials about popen2/3, smtplib/multipart and icq/jabber?
- Next by Date: Does any one recognize this binary data storage format
- Previous by thread: Re: Passing arguments to function - (The fundamentals are confusing me)
- Next by thread: Re: Passing arguments to function - (The fundamentals are confusing me)
- Index(es):
Relevant Pages
|