Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

a is b

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


sebas0 at gmail

Nov 4, 2009, 10:37 AM

Post #1 of 3 (65 views)
Permalink
a is b

I have a question from the pyar list that may have been discussed on this
list, but i didn't catch it.
Have some common objects been somewhat hardcoded into python, like some
integers as shown in the examples below? What other object have been
hardcoded (strings ,etc) and what was the criteria used to select them? Any
hints?
cheers,
- Seb

>>> p = 500
>>> q = 500
>>> p == q
True
>>> p is q
False
>>> n = 50
>>> m = 50
>>> n == m
True
>>> n is m
True
>>> p = 500; q = 500
>>> p is q
True

>>> for i in range(-20,258):
... a = i
... b = i+0
... if not (a is b): print i
...
-20
-19
-18
-17
-16
-15
-14
-13
-12
-11
-10
-9
-8
-7
-6
257


clp2 at rebertia

Nov 4, 2009, 10:42 AM

Post #2 of 3 (59 views)
Permalink
Re: a is b [In reply to]

On Wed, Nov 4, 2009 at 10:37 AM, Sebastian <sebas0[at]gmail.com> wrote:
> I have a question from the pyar  list that may have been discussed on this
> list, but i didn't catch it.
> Have some common objects been somewhat hardcoded into python, like some
> integers as shown in the examples below? What other object have been
> hardcoded (strings ,etc) and what was the criteria used to select them?  Any
> hints?

See recent thread on the subject:
http://www.mail-archive.com/python-list[at]python.org/msg264434.html

Cheers,
Chris
--
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


jitu.icfai at gmail

Nov 4, 2009, 10:29 PM

Post #3 of 3 (48 views)
Permalink
Re: a is b [In reply to]

Hi Sebas

>>> w = "q"
>>>a = "q"
>>>id(w)
11160864
>>>id(a)
11160864
>>> z = "big string"
>>> s = "big string"
>>> id(z)
13675120
>>> id(s)
13674520
This is applicable for number also.. , python caches is using same id for
small numbers and string.

Jitendra Kumar

On Thu, Nov 5, 2009 at 12:12 AM, Chris Rebert <clp2[at]rebertia.com> wrote:

> On Wed, Nov 4, 2009 at 10:37 AM, Sebastian <sebas0[at]gmail.com> wrote:
> > I have a question from the pyar list that may have been discussed on
> this
> > list, but i didn't catch it.
> > Have some common objects been somewhat hardcoded into python, like some
> > integers as shown in the examples below? What other object have been
> > hardcoded (strings ,etc) and what was the criteria used to select them?
> Any
> > hints?
>
> See recent thread on the subject:
> http://www.mail-archive.com/python-list[at]python.org/msg264434.html
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.