"is" in python

How do you check two objects are same or not ?
Yes id() builtin function provides you the identity of an object, just compare it
 
>>> a = "helloo"
>>> id(a)
140463901765824
>>> b = a
>>> id(a) == id(b)
True
 
But the best pythonic way to check objects is use 'is' operator.
>>> a = "heloo" 
>>> b = a
>>> a is b
True
 
But what is happening in the below example ??
>>> i = 1
>>> j = 1
>>> i is j
True
 
Why True ? i and j are two different objects !!
 
 >>> k = 1.0
>>> l = 1.0
>>> k is l
False

Works fine along with float, but not with int ???
 
Yes python caches the values of string and int for better efficiency so int strings with same values
will have same id, and hence “is” operator returns true in case of int and string.


String Example showing same id for different objects:
>>> a = "apple" 
>>> b = "apple"
>>> id(a)
140463901765824
>>> id(b)
140463901765824