🌐
W3Schools
w3schools.com › python › ref_dictionary_get.asp
Python Dictionary get() Method
Python Dictionaries Access Items ... Methods Dictionary Exercises Code Challenge Python If...Else · Python If Python Elif Python Else Shorthand If Logical Operators Nested If Pass Statement Code Challenge Python Match ... Python Functions Python Arguments Python *args / **kwargs Python Scope Python Decorators Python Lambda Python Recursion Python Generators Code Challenge Python Range ... Matplotlib Intro Matplotlib Get Started Matplotlib ...
🌐
W3Schools
w3schools.com › python › python_dictionaries.asp
Python Dictionaries
In Python 3.6 and earlier, dictionaries are unordered. When choosing a collection type, it is useful to understand the properties of that type. Choosing the right type for a particular data set could mean retention of meaning, and, it could mean an increase in efficiency or security. ... Coding fundamentals as a game. Bite-sized lessons and challenges. ... Ready to start your journey? Your streak is waiting. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
Discussions

python - Why dict.get(key) instead of dict[key]? - Stack Overflow
I came across the dict method get which, given a key in the dictionary, returns the associated value. For what purpose is this function useful? If I wanted to find a value associated with a key in a More on stackoverflow.com
🌐 stackoverflow.com
What does get() mean and do in Python?
There is no "get() method in Python" as though it were a universal feature of the language. Each class defines its own methods, and two methods with the same name in different classes are entirely separate from each other. As for the get() of a dictionary, this writeup is short and to the point. https://www.w3schools.com/python/ref_dictionary_get.asp get() on a dictionary returns the value of the key you specify (like mydict[key] does). But if the key doesn't exist, it returns None (instead of throwing an exception), or you can specify what value to return in that case via an optional second argument. More on reddit.com
🌐 r/learnpython
7
2
March 17, 2025
Beginner Tip - Use Dictionary .get() method to Improve Code Readability When Using Dictionaries
I'd also recommend reading into defaultdicts . They fit this use case quite well. More on reddit.com
🌐 r/pythontips
8
31
February 16, 2023
Is there a way to find a key in a dictionary with only knowing the value?
You will need to iterate: result = [key for key, value in my_dictionary.items() if value == 93] More on reddit.com
🌐 r/learnpython
11
13
October 28, 2022
🌐
Reddit
reddit.com › r/learnpython › what does get() mean and do in python?
r/learnpython on Reddit: What does get() mean and do in Python?
March 17, 2025 -

Hi, I am taking a more advance Python course at university and I have a difficult time understanding what the get() method does in Python. I know it is something to do with dictionaries but even after doing some research online, I still couldn't quite understand it fully. So can anyone please explain to me what the get() method does in Python in a simple definition, it would be helpful, thanks.

Using get() with nested dictionary. Apr 10, 2024
r/learnpython
2y ago
What does some_function.__get__ do? Dec 15, 2015
r/learnpython
10y ago
'Get' methods in Python Oct 26, 2019
r/learnpython
6y ago
More results from reddit.com
🌐
W3Schools
w3schools.com › python › python_ref_dictionary.asp
Python Dictionary Methods
Learn more about dictionaries in our Python Dictionaries Tutorial. ... Coding fundamentals as a game. Bite-sized lessons and challenges. ... Ready to start your journey? Your streak is waiting. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-get-method
Python Dictionary get() Method - GeeksforGeeks
April 18, 2026 - Example: In this example, here a value is retrieve from a dictionary using get(). ... Explanation: d.get('coding') returns the value linked to 'coding'. Since the key exists, its value is returned.
🌐
W3Schools
w3schools.am › python › ref_dictionary_get.html
Python Dictionary get() Method
HTML Certificate CSS Certificate JavaScript Certificate SQL Certificate Python Certificate jQuery Certificate PHP Certificate Bootstrap Certificate XML Certificate Get Certified » · W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding.
🌐
Codecademy
codecademy.com › docs › python › dictionaries › .get()
Python | Dictionaries | .get() | Codecademy
May 11, 2025 - The .get() method is a built-in dictionary method in Python that retrieves the value for a specified key from a dictionary. This method provides a safe way to access dictionary values without raising a KeyError when the key doesn’t exist.
🌐
Tutorialspoint
tutorialspoint.com › python › dictionary_get.htm
Python dictionary get() Method
The Python dictionary get() method is used to retrieve the value corresponding to the specified key. This method accept keys and values, where value is optional. If the key is not found in the dictionary, but the value is specified, then this method
Find elsewhere
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › dict › get.html
get — Python Reference (The Right Way) 0.1 documentation
Returns the value for key in the dictionary; if not found returns a default value · dict. get(key[, default])
🌐
GitHub
github.com › pydawan › w3schools-python-tutorial › blob › master › dictionaries.py
w3schools-python-tutorial/dictionaries.py at master · pydawan/w3schools-python-tutorial
# # Method Description ... a dictionary with the specified keys and values · # get() Returns the value of the specified key ·...
Author: pydawan
🌐
Career Karma
careerkarma.com › blog › python › python dictionary get: step-by-step guide
Python Dictionary Get: Step-By-Step Guide | Career Karma
December 1, 2023 - The syntax for the dict.get() method in Python is as follows: ... value is the value to return if the specified key does not exist. This defaults to None. This parameter is optional. You can retrieve items from a dictionary using indexing syntax.
🌐
Programiz
programiz.com › python-programming › methods › dictionary › get
Python Dictionary get()
Online Python Online JavaScript Online SQL Online Java Online HTML Online C Online C++ Online C# Online PHP Online Swift Online Kotlin Online TypeScript Online Go Online Rust Online Scala Online Dart Online R Online Ruby ... The get() method returns the value of the specified key in the dictionary.
🌐
Learn By Example
learnbyexample.org › python-dictionary-get-method
Python Dictionary get() Method - Learn By Example
April 20, 2020 - If key is in the dictionary, the method returns the value for key (no matter what you pass in as default). D = {'name': 'Bob', 'age': 25, 'job': 'Manager'} print(D.get('job', 'Developer')) # Prints Manager
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary
Python Dictionary - GeeksforGeeks
A value in a dictionary is accessed by using its key. This can be done either with square brackets [ ] or with the get() method.
Published: June 9, 2026
🌐
Cach3
w3schools.com.cach3.com › python › python_dictionaries.asp.html
Python Dictionaries - W3Schools
Python has a set of built-in methods that you can use on dictionaries. ... Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow Filter List Sort List · HTML CSS JavaScript SQL Python PHP jQuery Bootstrap XML Read More » ... If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: ... Your message has been sent to W3Schools...
Top answer
1 of 16
1716

It allows you to provide a default value if the key is missing:

dictionary.get("bogus", default_value)

returns default_value (whatever you choose it to be), whereas

dictionary["bogus"]

would raise a KeyError.

If omitted, default_value is None, such that

dictionary.get("bogus")  # <-- No default specified -- defaults to None

returns None just like

dictionary.get("bogus", None)

would.

2 of 16
245

What is the dict.get() method?

As already mentioned the get method contains an additional parameter which indicates the missing value. From the documentation

get(key[, default])

Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError.

An example can be

>>> d = {1:2,2:3}
>>> d[1]
2
>>> d.get(1)
2
>>> d.get(3)
>>> repr(d.get(3))
'None'
>>> d.get(3,1)
1

Are there speed improvements anywhere?

As mentioned here,

It seems that all three approaches now exhibit similar performance (within about 10% of each other), more or less independent of the properties of the list of words.

Earlier get was considerably slower, However now the speed is almost comparable along with the additional advantage of returning the default value. But to clear all our queries, we can test on a fairly large list (Note that the test includes looking up all the valid keys only)

def getway(d):
    for i in range(100):
        s = d.get(i)

def lookup(d):
    for i in range(100):
        s = d[i]

Now timing these two functions using timeit

>>> import timeit
>>> print(timeit.timeit("getway({i:i for i in range(100)})","from __main__ import getway"))
20.2124660015
>>> print(timeit.timeit("lookup({i:i for i in range(100)})","from __main__ import lookup"))
16.16223979

As we can see the lookup is faster than the get as there is no function lookup. This can be seen through dis

>>> def lookup(d,val):
...     return d[val]
... 
>>> def getway(d,val):
...     return d.get(val)
... 
>>> dis.dis(getway)
  2           0 LOAD_FAST                0 (d)
              3 LOAD_ATTR                0 (get)
              6 LOAD_FAST                1 (val)
              9 CALL_FUNCTION            1
             12 RETURN_VALUE        
>>> dis.dis(lookup)
  2           0 LOAD_FAST                0 (d)
              3 LOAD_FAST                1 (val)
              6 BINARY_SUBSCR       
              7 RETURN_VALUE  

Where will it be useful?

It will be useful whenever you want to provide a default value whenever you are looking up a dictionary. This reduces

 if key in dic:
      val = dic[key]
 else:
      val = def_val

To a single line, val = dic.get(key,def_val)

Where will it be NOT useful?

Whenever you want to return a KeyError stating that the particular key is not available. Returning a default value also carries the risk that a particular default value may be a key too!

Is it possible to have get like feature in dict['key']?

Yes! We need to implement the __missing__ in a dict subclass.

A sample program can be

class MyDict(dict):
    def __missing__(self, key):
        return None

A small demonstration can be

>>> my_d = MyDict({1:2,2:3})
>>> my_d[1]
2
>>> my_d[3]
>>> repr(my_d[3])
'None'
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.7 documentation
To avoid getting this error when trying to access a possibly non-existent key, use the get() method instead, which returns None (or a specified default value) if the key is not in the dictionary.
🌐
Real Python
realpython.com › python-dicts
Dictionaries in Python – Real Python
April 8, 2026 - Learn how dictionaries in Python work: create and modify key-value pairs using dict literals, the dict() constructor, built-in methods, and operators.
🌐
w3resource
w3resource.com › python › python-dictionary.php
Python Dictionary
>>> #Declaring a dictionary >>> dict = {1:20.5, 2:3.03, 3:23.22, 4:33.12} >>> #Access value using key >>> dict[1] 20.5 >>> dict[3] 23.22 >>> #Accessing value using get() method >>> dict.get(1) 20.5 >>> dict.get(3) 23.22 >>>
🌐
W3Schools
w3schools.com › python › python_dictionaries_loop.asp
Python - Loop Dictionaries
You can loop through a dictionary by using a for loop. When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well.