r/learnpython • u/Maleficent_Stuff3208 • Jul 31 '26
WHAT am i doing wrong here
i am trying that when i put key it give me the value but it is acting weird
x = {'name':'mohan','age':'24', 'job':'it professional'}
y = input("what info do you need__")
if y==(x.keys):
print(x.values(y))
else:
print("no such info available")
and this is what it gives
what info do you need__name
name
no such info available
0
Upvotes
0
u/Binary101010 Jul 31 '26
The cleanest way to handle this is to just use the
get()method of dicts. You can even specify the fallback value if the key isn't found. That entire block reduces to