A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Python Caches Integer object in some range
Joined: Aug 11, 2012
Sep 14, 2012 00:57:17
In a book 'Core Python Programming' I read that Python caches simple integer objects between a range(-1, 100) which may change..
But this is not same for the float..
So there was an exammple like this: -
a = 1 b = 1 id(a) == id(b) prints True c = 1.0 d = 1.0 id(c) == id(d) prints False
But when I ran this code in my Python interpreter, I got
value for both of them...
So, this mean my Python is caching both Integer and Float objects..
How is this happening??
Is this because of Version Difference?? I'm using Python 2.7..
It is sorta covered in the
JavaRanch Style Guide
subject: Python Caches Integer object in some range
Boxing, ==, and Equals()
casting - from Dan's mock casting1
Q on Integer()
Precision of float and double
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013