Post

PythonPython

A
Anusha V

Posted on 4th February 2023|20 views

0
votes

Python Dict Insert If Not Present

How do I insert/update a key within the dict if it is not there, by using python code?

 

Answers
P
divija reddy

Posted on 4th February 2023

You can do it like this

if key not in d: 

d[key] = value

 

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