0

fruit={'apple':'one','banana':'two','orange':'three'}
a='one'
if a in fruit.value():
    print(a,"was found!")

When I run this on python it shows: AttributeError: 'dict' object has no attribute 'value'

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jonathan Drukker
  • 119
  • 1
  • 2
  • 12

2 Answers2

2

The dictionary has no element called key(). What you're meant to use is keys() with an s at the end. This is how it should look like:

fruit={'apple':'one','banana':'two','orange':'three'}
a='apple'

if a in fruit.keys():
    print(f"Yes, key: '{a}' exists in dictionary")
Nimantha
  • 6,405
  • 6
  • 28
  • 69
The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24
1

Simply check it like this:

fruit={'apple':'one','banana':'two','orange':'three'}
a='apple'
if a in fruit:
    print(a,"was found!")
Walid
  • 718
  • 5
  • 13