What does the == operator actually do on a Python dictionary?

后端 未结 3 1889
谎友^
谎友^ 2020-12-03 04:14

Consider:

>>> a = {\'foo\': {\'bar\': 3}}
>>> b = {\'foo\': {\'bar\': 3}}
>>> a == b
True

According to the pyth

3条回答
  •  一生所求
    2020-12-03 05:09

    The dictionaries are equal if they have the same keys and the same values for each key.

    See some examples:

    dict(a=1, b=2) == dict(a=2, b=1)
    False
    
    dict(a=1, b=2) == dict(a=1, b=2, c=0)
    False
    
    dict(a=1, b=2) == dict(b=2, a=1)
    True
    

提交回复
热议问题