Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.05; 'float': 0.05; 'python': 0.09; '__future__': 0.09; 'integers': 0.09; 'notation': 0.09; 'resulting': 0.13; 'cases': 0.15; 'benjamin': 0.16; 'did.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 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; 'all,': 0.21; 'explicit': 0.22; 'object.': 0.22; 'example': 0.23; '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; 'division': 0.29; '(and': 0.32; 'gets': 0.32; 'int': 0.33; 'to:addr:python- list': 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; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'short': 0.39; 'where': 0.40; 'end': 0.40; 'think': 0.40; 'easy': 0.60; 'bring': 0.62; 'ever': 0.63; 'believe': 0.69; 'contrary': 0.71; '11:45': 0.84; '2013': 0.84; 'oscar': 0.84; 'careful': 0.91; 'ethan': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=uuwv92dkcA3HTURGEGqifjLWdPc9YRwM7g4O/UpI4B0=; b=aW29BKxg54n/Ck6dxYCIH0mp+bWpMl+lObxshcHP8XvIF9ITFv270Vdb/E9LkLk5nJ jAmtT935AevfcSxjDgqk9+jv5nrfBTj/XDKdI4kcuaN6WqYRSFflmb2gCK2Rvl5+G38d Ms2jU3tJVGBIhJbKZDfc1xINs8ND9m+xqBi9nxAvlHjtYTj7oUE9MCePcDBCX9/1c/VL D5lxznkVkGkDtAXB0kFFu8/aVtTyWtEZ01+ucKfdqKVdxple6OC/nhabEoFyfHu4hZSa tydCCbeg38R9MqMwJext1k9nUB9kNPoLde9PS1e6Ev8wntW0FF2jGxT//vziSE7MP4tf c+Dg== MIME-Version: 1.0 X-Received: by 10.58.50.7 with SMTP id y7mr9470982ven.24.1361755478791; Sun, 24 Feb 2013 17:24:38 -0800 (PST) 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> Date: Mon, 25 Feb 2013 12:24:38 +1100 Subject: Re: Python Newbie From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361755486 news.xs4all.nl 6880 [2001:888:2000:d::a6]:36812 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39847 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 :) 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. ChrisA