How to check if a key exists in a dictionary using Python

1 Answer

0 votes
dic = {'aa': 'python', 'bb': 'java', 'cc': 'php', 'dd': "c++"}

k = 'cc'
if k in dic.keys():
    print('yes')
else:
    print('no')

 
'''
run:
 
yes
 
'''

 



answered Dec 6, 2017 by avibootz

Related questions

2 answers 230 views
1 answer 200 views
2 answers 160 views
1 answer 174 views
1 answer 152 views
1 answer 183 views
...