<div dir="ltr">On 1 September 2013 03:31, Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com" target="_blank">wlfraed@ix.netcom.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 30 Aug 2013 23:07:47 -0700 (PDT), Fabrice Pombet <<a href="mailto:fp2161@gmail.com">fp2161@gmail.com</a>><br>

declaimed the following:<br>
<div class="im"><br>
>well, look at that:<br>
><br>
>a=(1,2)<br>
>a=2+3 ->a is an object and I have changed its type and value from outside. As far as I am concerned this is one hell of an encapsulation violation... Could you do this -strictly speaking- in Java or C++?<br>
<br>
</div>        There is where your major misunderstanding is...<br>
<br>
"a" is a NAME attached (bound) to an object. In the first statement, the<br>
object is the tuple (1,2). That object was not changed when you execute the<br>
second statement -- which is taking two integer objects and creating a new<br>
integer object having a value of '5', and then attaches the NAME "a" to the<br>
new object. If no other names are bound to the (1,2) object, it will be<br>
garbage collected.<br></blockquote><div><br></div><div>I'll try another way to explain it, using Java terminology(since Fabrice appears to be familiar with Java).</div><div><br></div><div>Object a = Arrays.asList(1, 2);  // a is a reference to the List<Integer> returned by Arrays.asList</div>
<div>a = Integer.valueOf(2 + 3);  // a is now a reference to the Integer returned by Integer.valueOf</div><div><br></div><div>You have not changed the type of 'a' in any way - you have simply changed what the name 'a' refers to. This is functionally identical to your Python code above,except that in Python you do not have to downcast the Object reference 'a' or use reflection to call methods on it or access it's members (think of it as Python does reflection automatically for you).</div>
<div><br></div><div>Tim Delaney</div></div></div></div>