dict2 = {'Name': 'sandeep', 'Age': 15, 'Class': '11th', 'school': 'GSBV'}
print(dict2)
if 'collage' in dict2.keys(): print(dict2['collage'])
else: print('no key found in dict')
print(dict2.setdefault('collage', 'this key do not exist in dict'))
if 'collage' in dict2.keys(): print(dict2['collage'])
else: print('no key found in dict')
OUTPUT
no key found in dict
this key do not exist in dict
this key do not exist in dict
It does not print
no key found in dict
but instead, it prints
this key do not exist in dict
in the last line, why is my program having this behavior?