Reputation: 351
>>> flob = {u'': [u''], u'DL': [u'DL'], u'Gender': [u'Both Sexes'], u'SQ': [u'SQ'], u'BP': [u'BP'], u'Location': [u'World Wide']}
>>> flob is dict
False
>>> flob == dict
False
>>> type(flob)
<type 'dict'>
I ask it if its type dict, it says false. I ask it what type it is, it says dict. Why?
Upvotes: 1
Views: 1680
Reputation: 61597
Is this orange the same thing as the concept of oranges in general?
Is this orange equal in value to the concept of oranges in general?
What kind of thing is this orange?
Upvotes: 3
Reputation: 362944
is
is used or identity comparison. See below for a hint - id
returns the memory location of an object and id(a) == id(b)
is analogous to a is b
. For type checks (which should be used sparingly), you want isinstance
.
>>> flob = {u'': [u''], u'DL': [u'DL'], u'Gender': [u'Both Sexes'], u'SQ': [u'SQ'], u'BP': [u'BP'], u'Location': [u'World Wide']}
>>> id(flob)
17665920
>>> id(dict)
8678496
>>> id(flob) == id(dict)
False
>>> type(flob) == dict
True
>>> isinstance(flob, dict)
True
Upvotes: 3
Reputation: 39913
Because you are comparing the object itself, the instance of dict
, with dict
... these two things are different entities. is
is used to determine if two variable names are pointing at the same object.
type({}) is dict # returns true.
a = {}
b = a
a is b # returns true
Upvotes: 8