Difference between dict.clear() and assigning {} in Python

后端 未结 8 917
我在风中等你
我在风中等你 2020-11-28 19:57

In python, is there a difference between calling clear() and assigning {} to a dictionary? If yes, what is it? Example:

d = {\"stuff\":\"         


        
8条回答
  •  一生所求
    2020-11-28 20:23

    As an illustration for the things already mentioned before:

    >>> a = {1:2}
    >>> id(a)
    3073677212L
    >>> a.clear()
    >>> id(a)
    3073677212L
    >>> a = {}
    >>> id(a)
    3073675716L
    

提交回复
热议问题