What's the difference between dict() and {}?

前端 未结 8 501
陌清茗
陌清茗 2020-12-12 13:53

So let\'s say I wanna make a dictionary. We\'ll call it d. But there are multiple ways to initialize a dictionary in Python! For example, I could do this:

8条回答
  •  佛祖请我去吃肉
    2020-12-12 14:30

    Funny usage:

    def func(**kwargs):
          for e in kwargs:
            print(e)
        a = 'I want to be printed'
        kwargs={a:True}
        func(**kwargs)
        a = 'I dont want to be printed'
        kwargs=dict(a=True)
        func(**kwargs)
    

    output:

    I want to be printed
    a
    

提交回复
热议问题