Write a Python Program to Check if a Key is Already Present in a Dictionary

Python Program to Check if a Key is Already Present in a Dictionary

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Check if a Key is Already Present in a Dictionary

Write a Python Program to Check if a Key is Already Present in a Dictionary

PROGRAM:Python Program to Check if a Key is Already Present in a Dictionary

/* Python Program to Check if a Key is Already Present in a Dictionary */

Using in keyword

my_dict = {1: 'a', 2: 'b', 3: 'c'}

if 2 in my_dict:
    print("present")

Output

present

Leave a Reply

Your email address will not be published. Required fields are marked *