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 219 views
1 answer 194 views
2 answers 151 views
1 answer 165 views
1 answer 148 views
1 answer 173 views
...