Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!feeds.news.ox.ac.uk!news.ox.ac.uk!zen.net.uk!hamilton.zen.co.uk!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; 'classes.': 0.07; 'implements': 0.07; 'method,': 0.07; 'referring': 0.07; 'def': 0.10; 'language': 0.14; 'properly': 0.15; 'coercion.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'wanted.': 0.16; 'wrote:': 0.17; 'refers': 0.17; 'typing': 0.17; 'subject:problem': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'implemented': 0.27; 'interface': 0.27; 'necessary,': 0.29; 'function': 0.30; 'could': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'depends': 0.36; 'method': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'cast': 0.65 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 02 Feb 2013 11:19:41 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Floating point calculation problem References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359829190 news.xs4all.nl 6866 [2001:888:2000:d::a6]:60401 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38084 On 02/02/2013 08:48 AM, Schizoid Man wrote: > Also, if the cast is necessary, then now exactly does the dynamic typing > work? Dynamic typing isn't referring to numeric type coercion. It refers to the fact that a name can be bound to an object of any type. So if you made a function like this: def add (num1, num2): return num1 + num2 num1 and num2 could be any type. Even a custom type if you wanted. This function would work properly on any type that had implemented the __add__ method. And whether or not num2 has to be the same type as num1 depends on whether the num1 type has implemented an __add__ method that can deal with the type of num2. Another case where dynamic typing comes into play is in a case know as duck typing: def squeeze_duck (duck): // return the quack return duck.squeeze() duck can be of any type as well, but as long as it implements the squeeze method, this function will work with an object of that type. In a language like C#, duck-typing can only be emulated by using interface classes.