Post

PythonPython

s
sreelu 123

Posted on 4th March 2024|12 views

0
votes

Python Dictionary Contains

How do you check if an item is in a dictionary python?

Answers
P
chris bons

Posted on 4th March 2024

You can use in operator to check if an item is in a dictionary let me explain it to you by a simple example:

def main():

months={

‘Jan’ = 1,

‘March’ = 2,

‘June’ = 3

}

#checking for Jan

if ‘Jan’ in months:

print(months[‘Jan’])

if _name_ == ‘_main_’:

main()

Output:

1

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos