DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: Return None if Dictionary key is not available

You can use dict.get()

value = d.get(key)

which will return None if key is not in d. You can also provide a different default value that will be returned instead of None:

value = d.get(key, "empty")

Top comments (0)