#!/usr/bin/env python
# coding: utf-8
# #The difference between is
and ==
.
# When programmng, you will often want to compare things. However, the behaviour of the python interpreter doesn't always meet expectations.
# In[1]:
x = 5
# In[2]:
y = 5
# In[3]:
x == 5
# In[4]:
x is y
# In[5]:
a = [0, 1, 2]
# In[6]:
b = [0, 1, 2]
# In[7]:
a == b
# In[8]:
a is b
# In[11]:
b = a
print(a)
print(b)
# In[12]:
a == b
# In[13]:
a is b
# In[14]:
a[0] = 100
# In[16]:
print(b[0])
# In[17]:
b = a[:]
# In[18]:
b == a
# In[19]:
b is a
# In[23]:
x = 1e5
print(x)
# In[24]:
y = x
# In[25]:
x == y
# In[26]:
x is y
# In[27]:
x += 1
# In[30]:
print(x)
print(y)
# In[31]:
x is y
# In[32]:
x == y
# In[34]:
x = 1000
y = 1000
# In[35]:
x == y
# In[36]:
x is y
# In[37]:
y = int(y)
# In[38]:
x == y
# In[39]:
x is y
# In[41]:
x = 5.0
# In[43]:
y = 5
# In[44]:
x == y
# In[45]:
x is y
# Source: http://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python