What is a mapping object, according to dict type?

后端 未结 5 1737
無奈伤痛
無奈伤痛 2020-12-11 15:35

The documentation lists 3 ways for creating a dict instance:

class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)

5条回答
  •  旧时难觅i
    2020-12-11 15:43

    It's the best answer for your question:

    https://docs.python.org/2/library/stdtypes.html#typesmapping

    It's the simplest example of mapping: {}

    If you want to create a custom mapping type, you may inherit it from base dict and overwrite __getitem__ magic method(it depends on your needs)

提交回复
热议问题