How to return a value from a dictionary when key is not present with Python

1 Answer

0 votes
dic = {"python": 5,
       "java": 6,
       "dart": 7,
       "c": 2 }

print(dic.get('cpp', -1))

print(dic.get('python', -1))





'''
run:

-1
5

'''

 



answered Feb 23, 2023 by avibootz
...