"Gregory Piñero" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> how references work in Python
'references' are an implementation detail and a metaconcept used to talk
about Python but are not part of the language spec itself.
> when passing arguments into functions?
Python does
Gregory Piñero wrote:
> So what if I do want to share a boolean variable like so:
Well, the easiest way is to wrap it in a list:
mybool = [True]
mybool[0] = False
mybool[0] = True
and so on.
Alternately, what is this boolean attached to that's so significant?
Sharing an arbitrary boolean, with
Thanks everyone. I understand now. Everything is a reference, all
that matters is whether I can go inside the "cubbyhole" and change
something. Immutables don't allow this.
So what if I do want to share a boolean variable like so:
sharedbool=True
class cls1:pass
cl=cls1()
cl.sharedbool1=shared
Christopher Subich wrote:
> Rocco Moretti wrote:
>
>> 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.
>
>
> +1 MOTW (Metaphor of the Week)
Thanks, but please note it's not really mine - I've seen it s
Dennis Lee Bieber wrote:
> On Tue, 09 Aug 2005 10:39:29 -0500, Rocco Moretti
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>>Change it to "the object referenced by y is assigned to the name of x",
>>and you're closer to the truth.
>
> In a more simplistic view, I'
Rocco Moretti wrote:
> 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.
+1 MOTW (Metaphor of the Week)
--
http://mail.python.org/mailman/listinfo/python-list
infidel wrote:
>>in Python equality rebinds the name
>
>
> Assignment (=) rebinds the name. Equality (==) is something else
> entirely.
Good catch. I was thinking of it as the "equals" operator.
--
http://mail.python.org/mailman/listinfo/python-list
Dennis Lee Bieber wrote:
> In a more simplistic view, I'd reverse the phrasing... The name
> "x" is assigned to the object "y" (implying it is no longer attached to
> whatever used to have the name)
No, because that'd imply that the object 'y' somehow keeps track of the
names assigned to it
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 someti
> Does that mean Python functions aren't always byref,
> but are sometimes byval for nonmutables?
Don't think of it as byref or byval (as they are used in Visual Basic).
All parameters are passed the same way: by reference instead of by copy.
It's a little difficult to get your head around, but
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. Does
that mean Python functions aren't always byref, but are sometimes
byval for nonmutables?
-Greg
On 8/9/05, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On
> in Python equality rebinds the name
Assignment (=) rebinds the name. Equality (==) is something else
entirely.
--
http://mail.python.org/mailman/listinfo/python-list
Christopher Subich wrote:
> Gregory Piñero wrote:
>
>> Hey guys, would someone mind giving me a quick rundown of how
>> references work in Python when passing arguments into functions? The
>> code below should highlight my specific confusion:
This URL is always tossed out:
http://starship.pytho
Gregory Piñero wrote:
> Hey guys, would someone mind giving me a quick rundown of how
> references work in Python when passing arguments into functions? The
> code below should highlight my specific confusion:
All arguments are passed by reference, but in Python equality rebinds
the name.
>
>
Hey guys, would someone mind giving me a quick rundown of how
references work in Python when passing arguments into functions? The
code below should highlight my specific confusion:
bool1=True
lst1=[1,2,3]
def func1(arg1): arg1.append(4)
def func2(arg1): arg1=False
>>func1(lst1)
>>lst1
[1,2,
15 matches
Mail list logo