Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
You should use the get() method from the dict class
get()
dict
d = {} r = d.get( 'missing_key', None )
This will result in r == None. If the key isn't found in the dictionary, the get function returns the second argument.
r == None
d = {} r = d.get('missing_key', None)
You should use the get()get() method from the dictdict class
This will result in r == Noner == None. If the key isn't found in the dictionary, the get function returns the second argument.