<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It might be helpful to think of “x” in your example as a named reference to an object of type int with the value 5. Later, you tell the runtime to use “x” as a named reference to an object of type str with the value “Douglas”. When there are no longer any references to the object of type int with value 5, it will basically be garbage collected.<div class=""><br class=""></div><div class="">There are some implementation details here that might be interesting. The “id” of each object is unique, and in C Python is the address of the object in memory (pointer)[1]. Also, all integers up to 255 (IIRC, might be slightly different) have fixed memory locations as an optimization since they are so often used[2].</div><div class=""><br class=""></div><div class="">Check out this REPL output:</div><div class=""><br class=""></div><div class="">``` python</div><div class="">Python 2.7.6 (default, Sep  9 2014, 15:04:36) <br class="">[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin<br class="">Type "help", "copyright", "credits" or "license" for more information.<br class="">>>> x = 5<br class="">>>> type(x)<br class=""><type 'int'><br class="">>>> id(x)<br class="">140325469366472<br class="">>>> id(5)<br class="">140325469366472<br class="">>>> x = "Douglas"<br class="">>>> type(x)<br class=""><type 'str'><br class="">>>> id(x)<br class="">4439541392<br class="">>>> id("Douglas")<br class="">4439541392<br class="">>>> del(x)<br class="">>>> x<br class="">Traceback (most recent call last):<br class="">  File "<stdin>", line 1, in <module><br class="">NameError: name 'x' is not defined<br class="">>>> id("Douglas")<br class="">4439541392<br class=""></div><div class="">>>> for i in range(10):<br class="">...     print id(i)<br class="">... <br class="">140511741515904<br class="">140511741515880<br class="">140511741515856<br class="">140511741515832<br class="">140511741515808<br class="">140511741515784<br class="">140511741515760<br class="">140511741515736<br class="">140511741515712<br class="">140511741515688</div><div class="">```</div><div class=""><br class=""></div><div class="">Note that even though I’ve “deleted” x, the object it refers to is still in memory. It hasn’t been garbage collected and deallocated yet. Also note how the location of the object of type int with value 5 is the same as x when x = 5. Also note how memory locations for small ints are sequential (generated when starting the interpreter) and that the size of an int object in Python is 24 bytes.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">1. <a href="https://docs.python.org/2/library/functions.html#id" class="">https://docs.python.org/2/library/functions.html#id</a></div><div class="">2. <a href="https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/" class="">https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/</a></div><div class=""><br class=""></div><div class=""><br class=""><div apple-content-edited="true" class="">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div class="">Chris Foresman</div><div class=""><a href="mailto:chris@chrisforesman.com" class="">chris@chrisforesman.com</a></div><div class=""><br class="khtml-block-placeholder"></div><br class="Apple-interchange-newline"></span>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On May 18, 2015, at 11:09 AM, Lewit, Douglas <<a href="mailto:d-lewit@neiu.edu" class="">d-lewit@neiu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><div class=""><div class=""><font size="4" class="">But in Python you can!  Which is so cool!  You can do this:<br class=""><br class=""></font></div><font size="4" class="">x = 5<br class=""><br class=""></font></div><font size="4" class="">(But later in the program.)<br class=""><br class=""></font></div><font size="4" class="">x = "Douglas"<br class=""><br class=""></font></div><font size="4" class="">No problem.<br class=""><br class=""></font></div><font size="4" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">I guess I'm a little confused by the difference between static vs. dynamic and weak vs. strong typing.  Okay Rob, I need a lesson here!   :-)</font></div></blockquote></div><br class=""></div></body></html>