[Python] Nested get function

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I need a clarification on the built-in function get. The example is from here. The code:

    test_dict = {'Gfg' : {'is' : 'best'}}
    res = test_dict.get('Gf', {}).get('is')
    print("The nested safely accessed value is : " + str(res))


    I understand that get fn is strictly for retrieving values for a given key in a dictionary.

    1. What is the purpose of including {} in the outer get fn?
    2. In a nested get function, does the get fn work from inner to out or vice-versa?

    Continue reading...

Compartilhe esta Página