[Python] Access dict key and return None if doesn't exist

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

  1. Stack

    Stack Membro Participativo

    In Python what is the most efficient way to do this:

    my_var = some_var['my_key'] | None


    ie. assign some_var['my_key'] to my_var if some_var contains 'my_key', otherwise make my_var be None.

    Continue reading...

Compartilhe esta Página