I'm trying to learn why the following does not work:
I have a dictionary;
ex = {'CA':'San Francisco', 'NV':'Las Vegas'}
I tried to use if else
statement to get 'yes'
:
>>> if ex['CA'] is 'San Francisco':
... print 'yes'
... else:
... print 'no'
...
no
>>>
>>>
>>> if ex['CA'] == 'San Francisco' is True:
... print 'yes'
... else:
... print 'no'
...
no
>>> if ex['CA'] == 'San Francisco' is True:
... print 'yes'
...
>>>
Here, I don't get 'yes'
I want to understand why I'm not getting 'yes'
>>> ex['CA'] == 'San Francisco'
True
>>> ex['CA']
'San Francisco'
What would be the other ways if I want to use a conditional statement of key of dictionary equals to some value?