pythonrag

J

Jason Friedman

I saw this posted in the July issue but did not see any follow-up there:

$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 
I

Irmen de Jong

Jason Friedman ha scritto:
I saw this posted in the July issue but did not see any follow-up there:

$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
a = 500
b = 500
a == b True
a is b False
p = 50
q = 50
p == q True
p is q
True

LOL

I fail to see the fun?
Remember that everything in Python is an object, even integers.
For integers, I believe Python creates the first 100 integer objects and reuses them.
Larger integers are created when needed, and are different objects.
The example also shows why it usually is wrong to use object comparison ('is') when you
really mean equality (==).

-irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top