Using "get()" to Return a Default Value from a Python Dict

Published: 13 September 2016
on channel: Real Python
38,901
627

Here's a common situation working with dictionaries in Python: You want to look up the value of a key and if the key doesn't exist then you want to fall back to a default value.

There's many different ways to deal with that and some are considered anti-patterns. One of the best solutions is to use the "get()" method and its ability to pass on a default value. This video explains how to get better at working with dicts by learning how to use "get()" more effectively :) Also check out my tutorial here which contains some more background info on the topic: https://dbader.org/blog/python-dict-g...

► Weekly Tips for Python Developers: https://dbader.org/newsletter


Watch video Using "get()" to Return a Default Value from a Python Dict online without registration, duration hours minute second in high quality. This video was added by user Real Python 13 September 2016, don't forget to share it with your friends and acquaintances, it has been viewed on our site 38,90 once and liked it 62 people.