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
  • 5,793
  • 5
  • 23
  • 56
Jonathan Drukker
  • 109
  • 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
  • 5,793
  • 5
  • 23
  • 56
The Pilot Dude
  • 1,798
  • 2
  • 4
  • 22
1

Simply check it like this:

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