How/why does set() in {frozenset()} work?

后端 未结 2 923
说谎
说谎 2020-12-17 14:37

Even though sets are unhashable, membership check in other set works:

>>> set() in {frozenset()}
True

I expected TypeError:

2条回答
  •  鱼传尺愫
    2020-12-17 14:56

    The last line of the documentation for sets discusses this:

    Note, the elem argument to the __contains__(), remove(), and discard() methods may be a set. To support searching for an equivalent frozenset, a temporary one is created from elem.

提交回复
热议问题