For the following code, str is variable of unicode type but
str is unicode # returns false
isinstance(str, unicode) # returns true
Why is is return false?
is operator is used to check if both the objects are one and the same, whereas isinstance is used to check if the second parameter appears anywhere in the inheritance chain of the first parameter.
So, when you do something like this
print(u"s" is unicode)
you are actually checking if u"s" is the unicode, but when you do
print(isinstance(u"s", unicode))
you are checking if u"s" is of type unicode and the latter is actually True.
isis checking for object equality.s/equality/identity/