Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'languages,': 0.04; 'subject:Python': 0.05; 'float': 0.05; 'statically': 0.07; 'python': 0.09; '__future__': 0.09; 'ambiguity': 0.09; 'integers': 0.09; 'notation': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.10; 'resulting': 0.13; '(like': 0.15; 'cases': 0.15; 'benjamin': 0.16; 'both.': 0.16; 'cc:name:python list': 0.16; 'did.': 0.16; 'highlighted': 0.16; 'languages)': 0.16; 'literal.': 0.16; 'too).': 0.16; 'variable.': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'integer': 0.17; '>>>': 0.18; 'feb': 0.19; 'issue.': 0.20; 'all,': 0.21; 'explicit': 0.22; 'object.': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'am,': 0.27; '3.0': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; '>>>>': 0.29; 'attempted': 0.29; 'division': 0.29; "i'm": 0.29; '(and': 0.32; 'gets': 0.32; 'int': 0.33; 'languages': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'direction': 0.35; 'expected': 0.35; 'received:209.85.220': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'should': 0.36; 'possible': 0.37; 'does': 0.37; 'two': 0.37; 'ones': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'object': 0.38; 'some': 0.38; 'short': 0.39; 'where': 0.40; 'end': 0.40; 'think': 0.40; 'easy': 0.60; 'bring': 0.62; 'ever': 0.63; 'information': 0.63; 'believe': 0.69; 'contrary': 0.71; '11:45': 0.84; '2013': 0.84; 'oscar': 0.84; 'glad': 0.86; 'careful': 0.91; 'ethan': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=byCEtPb+w0IH8GVqkkCfp9s0XzHw3ZW81xlP4Rpo7Eg=; b=J82/J8enKWZpFIr15s3nLU6PNqva2cGs7D688LvXshC3bo6tTOb6DAWQFqm6MNCf1q zPggCAaDyf/E02ESC4XeNMLlR+6fwODlq297Qq3TViMStSrcUnX/WI7PYp76PMUbzdJa FNDikBvC4OHi9pJzqU8eqMfE5d8VGaHkCnxeyaKMrbSCry3e+wGK7v2La3oSjg+lGVgB rkibiCUmvTwfuKrLNonUWONy00uJgZFz02ihN5/K1milQzRNJKs598j8/F3/7fCc5tVt VbORBNJiEWDd8n+ViBW9lNN6AT+G1peuknZrmVyTsPk5DdUc+wYFiEbf/M5Ip/zgWI6T KBGw== X-Received: by 10.220.220.134 with SMTP id hy6mr9119886vcb.2.1361756700002; Sun, 24 Feb 2013 17:45:00 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> <9p1ii899tkalvfd1cl7sneoqa9t1cqh4oj@invalid.netcom.com> <5129482F.3080402@gmail.com> <512a5199$0$29998$c3e8da3$5496439d@news.astraweb.com> <5a3bf25b-a08b-4084-a940-e1fd05a1045d@googlegroups.com> <2e9471ad-8320-4f7f-80ba-cd5a7f8f013d@googlegroups.com> From: Oscar Benjamin Date: Mon, 25 Feb 2013 01:44:39 +0000 Subject: Re: Python Newbie To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361756708 news.xs4all.nl 6887 [2001:888:2000:d::a6]:59488 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39855 On 25 February 2013 01:24, Chris Angelico wrote: > On Mon, Feb 25, 2013 at 11:45 AM, Oscar Benjamin > wrote: >> On 25 February 2013 00:08, wrote: >> Chris Angelico wrote: >>>> For example (I believe it's already been mentioned) "declaring" intX with some integer value does *nothing* to maintain >>>> >>>> X as an integer: >>>> >>>> --> intX = 32 >>>> >>>> --> intX = intX / 3.0 >>>> >>>> --> intX >>>> >>>> 10.6666666666 >>>> >>> >>> Yes I did see that it is possible to redefine the type of a variable. But I don't think I would ever do this intentionally; need to be really careful with Python. > >> The trickier cases are ones where two types are very similar and can >> be used similarly in most, but not all, situations. An example of this >> would be the one that Chris has highlighted where an object that you >> expected to be an int is actually a float. I find that I need to be >> careful when using division on quantities that I expected to be >> integers (true in all languages) and careful about the notation used >> in a numeric literal. Once you get used to it, you will find it easy >> to see that the '.0' that Chris appended was deliberate in order to >> control the type of the resulting object. > > Once again, Ethan gets the short end of the citations stick... > 'twarn't me wrote that, he did. Not that it's at all contrary to my > views, and I might well have said it if he hadn't, but credit should > go his direction :) Apologies to you both. The information was missing and I attempted to fill it in but got it wrong. > Note though that in Python 3, you don't need the explicit .0 to force > it to float (and __future__ can bring that to Python 2 too). 32/3 -> > 10.66666, int/int->float. That's true and I'm very glad of this change in Python 3. However other issues of float/int ambiguity remain for those (like me) who are particularly concerned with numbers and their accuracy/exactness. So it is still necessary in Python 3 to be careful around this issue. While it is an issue in all languages, it is one that is often easier to deal with in statically typed languages than in Python. Oscar