Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52348

Re: Python Basic Doubt

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <i.am.songoku@gmail.com>
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; 'operator': 0.03; 'cpython': 0.05; 'subject:Python': 0.06; 'cache': 0.07; 'correct.': 0.07; 'none,': 0.07; 'variables': 0.07; 'assigning': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'question.': 0.14; '"is"': 0.16; '-tkc': 0.16; 'caches': 0.16; 'false:': 0.16; 'ironpython': 0.16; 'numbers).': 0.16; 'tim,': 0.16; 'to:addr:python.list': 0.16; 'to:addr:tim.thechases.com': 0.16; 'to:name:tim chase': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; '&gt;&gt;&gt;': 0.24; 'integer': 0.24; "shouldn't": 0.24; 'versions': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '&gt;': 0.26; 'compare': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'tim': 0.29; 'compared': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'chase': 0.31; 'exceptions': 0.31; 'ok.': 0.31; 'done.': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'i.e.': 0.36; 'doing': 0.36; 'thanks': 0.36; 'possible': 0.36; 'should': 0.36; 'skip:& 10': 0.38; 'pm,': 0.38; 'anything': 0.39; 'future': 0.60; 'new': 0.61; 'range': 0.61; "you're": 0.61; 'more': 0.64; 'different': 0.65; 'taking': 0.65; 'behavior': 0.77; '257': 0.84; 'location?': 0.84; 'colleagues': 0.97; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PwpfKRaKYtGN6hQUZybsE5iYe1EIPDEnoBRGtky1hjs=; b=VDnfBJkQIwyZtWDvuht48dinKXT+QfD92ZG4qEiteWiDj7nmMfgBAiq04JzBGERS0u /939J8xvqrmlgVLtXsfaTrGiYPYkA1zh/e7XvUrWOHy/ZnDVdGirbyDXoYB5IdJA793c Fz8c6nXv/QGSLQvEb8YvUyXRSsUstzfVr3SDChBmYUYVWLYlTukj+AoRzNrHln4t3lwN ugYKtGMwLTTfZPhHr93l2WG++pWy+EMcUMUYaNvvxGQp8Z2BYD/aNyxPm3pI0eXOdHk9 u02OJ8qd82MT9Y3eUTFA/7wzxzCxPgyWtW6zKGo+wVaOOrqcnXLj63RxZY2NxauK5xqu HDQg==
MIME-Version 1.0
X-Received by 10.180.189.9 with SMTP id ge9mr3484358wic.52.1376190580038; Sat, 10 Aug 2013 20:09:40 -0700 (PDT)
In-Reply-To <20130810114040.6ac78fe8@bigbox.christie.dr>
References <CAL0E0u6wO_UBniWoSpePvhKhPDG_nf4p1rqYYrGwzoHTqp6ZHA@mail.gmail.com> <20130810114040.6ac78fe8@bigbox.christie.dr>
Date Sun, 11 Aug 2013 08:39:39 +0530
Subject Re: Python Basic Doubt
From Krishnan Shankar <i.am.songoku@gmail.com>
To Tim Chase <python.list@tim.thechases.com>
Content-Type multipart/alternative; boundary=001a11c34302aaa18904e3a35601
X-Mailman-Approved-At Sun, 11 Aug 2013 05:12:51 +0200
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.455.1376190773.1251.python-list@python.org> (permalink)
Lines 135
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376190773 news.xs4all.nl 15872 [2001:888:2000:d::a6]:39086
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52348

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Thanks Tim,

This takes me to one more question.

'is' operator is used to compare objects and it should not be used to
compare data.

So can it be compared with 'False'.

i.e. Is this code possible

if a is False:
    print 'Yes'
if b is False:
    print 'No'

Because i recommended this should not be done. But my colleagues say it is
correct.

Regards,
Krishnan


On Sat, Aug 10, 2013 at 10:10 PM, Tim Chase
<python.list@tim.thechases.com>wrote:

> On 2013-08-10 21:03, Krishnan Shankar wrote:
> > >>> a=10
> > >>> id(a)
> > 21665504
> > >>> b=a
> > >>> id(b)
> > 21665504
> > >>> c=10
> > >>> id(c)
> > 21665504
> >
> > I am actually assigning new value to c. But from the value of id()
> > all three variables take same location. With variables a and b it
> > is ok. But why c taking the same location?
>
> As an internal optimization, CPython caches small integer values
>
>   >>> a = 256
>   >>> b = 256
>   >>> a is b
>   True
>   >>> a = 257
>   >>> b = 257
>   >>> a is b
>   False
>
> Because it's an internal implementation detail, you shouldn't count
> on this behavior (Jython or Cython or IronPython may differ; or
> future versions of Python may cache a different range of numbers).
>
> Generally, if you are using the "is" operator to compare against
> anything other than None, you're doing it wrong. There are exceptions
> to this, but it takes knowing the particulars.
>
> -tkc
>
>
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python Basic Doubt Krishnan Shankar <i.am.songoku@gmail.com> - 2013-08-11 08:39 +0530

csiph-web