[Python] Why do we need a dict.update() method in python instead of just assigning the values...

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

  1. Stack

    Stack Membro Participativo

    So the reasons to use update() method is either to add a new key-value pair to current dictionary, or update the value of your existing ones.

    But wait!?

    Aren't they already possible by just doing:

    >>>test_dict = {'1':11,'2':1445}
    >>>test_dict['1'] = 645
    >>>test_dict
    {'1': 645, '2': 1445}
    >>>test_dict[5]=123
    >>>test_dict
    {'1': 645, '2': 1445, 5: 123}


    When would it be crucial to use it?

    Continue reading...

Compartilhe esta Página