[Chicago] Python for mortgages???

Thomas Johnson thomas.j.johnson at gmail.com
Tue May 19 01:23:13 CEST 2015


Wikipedia might help clarify:


   - The object-oriented programming languages Smalltalk
   <https://www.wikiwand.com/en/Smalltalk>, Perl
   <https://www.wikiwand.com/en/Perl>, JavaScript
   <https://www.wikiwand.com/en/JavaScript>, Ruby
   <https://www.wikiwand.com/en/Ruby_(programming_language)>, Python
   <https://www.wikiwand.com/en/Python_(programming_language)>, and Self
   <https://www.wikiwand.com/en/Self_(programming_language)> are all
   "strongly typed" in the sense that typing errors are prevented at runtime
   and they do little implicit type conversion
   <https://www.wikiwand.com/en/Type_conversion>, but these languages make
   no use of static type checking: the compiler does not check or enforce type
   constraint rules. The term duck typing
   <https://www.wikiwand.com/en/Duck_typing> is now used to describe
the dynamic
   typing <https://www.wikiwand.com/en/Dynamic_typing> paradigm used by the
   languages in this group.

(https://www.wikiwand.com/en/Strong_and_weak_typing)


On Mon, May 18, 2015 at 5:54 PM Chris Foresman <foresmac at gmail.com> wrote:

> 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.
>
> 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].
>
> Check out this REPL output:
>
> ``` python
> Python 2.7.6 (default, Sep  9 2014, 15:04:36)
> [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> x = 5
> >>> type(x)
> <type 'int'>
> >>> id(x)
> 140325469366472
> >>> id(5)
> 140325469366472
> >>> x = "Douglas"
> >>> type(x)
> <type 'str'>
> >>> id(x)
> 4439541392
> >>> id("Douglas")
> 4439541392
> >>> del(x)
> >>> x
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'x' is not defined
> >>> id("Douglas")
> 4439541392
> >>> for i in range(10):
> ...     print id(i)
> ...
> 140511741515904
> 140511741515880
> 140511741515856
> 140511741515832
> 140511741515808
> 140511741515784
> 140511741515760
> 140511741515736
> 140511741515712
> 140511741515688
> ```
>
> 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.
>
>
> 1. https://docs.python.org/2/library/functions.html#id
> 2. https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/
>
>
> Chris Foresman
> chris at chrisforesman.com
>
>
>
> On May 18, 2015, at 11:09 AM, Lewit, Douglas <d-lewit at neiu.edu> wrote:
>
> But in Python you can!  Which is so cool!  You can do this:
>
> x = 5
>
> (But later in the program.)
>
> x = "Douglas"
>
> No problem.
>
> 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!   :-)
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150518/ad2e4d5f/attachment-0001.html>


More information about the Chicago mailing list