[Python] Is there a difference between using a dict literal and a dict constructor?

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024.

  1. Stack

    Stack Membro Participativo

    Using PyCharm, I noticed it offers to convert a dict literal:

    d = {
    'one': '1',
    'two': '2',
    }




    into a dict constructor:

    d = dict(one='1', two='2')




    Do these different approaches differ in some significant way?

    (While writing this question I noticed that using dict() it seems impossible to specify a numeric key .. d = {1: 'one', 2: 'two'} is possible, but, obviously, dict(1='one' ...) is not. Anything else?)

    Continue reading...

Compartilhe esta Página