# Relation between Equality(= =) and Identity (is) operators

We have seen that if values of two variables are same,

a=10

b=10

a==b  and a is b

will return true

But it is not always true.

There are some cases where two variables have same value but they return different results. It happens because there are few cases where Python creates two different objects having same value .These cases are:

• Complex values
• Floating point values
• Long integer values

When we read a string value, it is always assigned a different id.

 In:  str1=’lovejot’ In:  str2=input(‘Enter your name: ‘) Enter your name: lovejot In:  str1==str2 Out: True In: str1 is str2 Out: False

Note: In above Python statements we can see that str1 and str2 contain same value but str1 is str2 returns false because Python allocated different ids to variables str1 and str2

## 2. Complex Values

Complex values are always assigned different ids even for same values.

 In:  value1=2+5j In:  value2=2+5j In:  value1 == value2 Out: True  In:  value1 is value2 Out: False In:  id(value1),id(value2) Out: (164643136, 189130944)

Note: In above Python statements we can see that variables value1 and value 2 contain same value but value1 is value2 returns false because Python allocated different ids to variables value1 and value2.

## 3. Floating point Values

Floating point  values are always assigned different ids even for same values.

 In:  var1=2.5 In:  var2=2.5 In:  var1 == var2 Out: True In:  var1 is var2 Out: False In:  id(var1),id(var2) Out: (198464336, 198464464)

Note: In above Python statements we can see that variables var1 and var 2 contain same value but var1 is var2 returns false because Python allocated different ids to variables val1 and val2.

## 4. Very big integer Values

Small integer values are assigned same id by Python but long integer values are always assigned different ids even for same values.

 In:  var1=99999 In:  var2=99999 In:  var1 == var2 Out: True In:  var1 is var2 Out: False In:  id(var1),id(var2) Out: (198467056, 198465040)

Note: In above Python statements we can see that variables var1 and var 2 contain same value but var1 is var2 returns false because Python allocated different ids to variables val1 and val2.