File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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..
I agree. Here's the link:
subject: Python Caches Integer object in some range
Boxing, ==, and Equals()
Precision of float and double
Q on Integer()
casting - from Dan's mock casting1
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015