用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](iter.xhtml "迭代器协议") | - [上一页](sequence.xhtml "Sequence Protocol") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python/C API 参考手册](index.xhtml) » - [抽象对象层](abstract.xhtml) » - $('.inline-search').show(0); | # Mapping Protocol See also [`PyObject_GetItem()`](object.xhtml#c.PyObject_GetItem "PyObject_GetItem"), [`PyObject_SetItem()`](object.xhtml#c.PyObject_SetItem "PyObject_SetItem") and [`PyObject_DelItem()`](object.xhtml#c.PyObject_DelItem "PyObject_DelItem"). int `PyMapping_Check`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)Return `1` if the object provides mapping protocol or supports slicing, and `0` otherwise. Note that it returns `1` for Python classes with a [`__getitem__()`](../reference/datamodel.xhtml#object.__getitem__ "object.__getitem__") method since in general case it is impossible to determine what the type of keys it supports. This function always succeeds. Py\_ssize\_t `PyMapping_Size`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)Py\_ssize\_t `PyMapping_Length`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)Returns the number of keys in object *o* on success, and `-1` on failure. This is equivalent to the Python expression `len(o)`. [PyObject](structures.xhtml#c.PyObject "PyObject")\* `PyMapping_GetItemString`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, const char *\*key*)*Return value: New reference.*Return element of *o* corresponding to the string *key* or *NULL* on failure. This is the equivalent of the Python expression `o[key]`. See also [`PyObject_GetItem()`](object.xhtml#c.PyObject_GetItem "PyObject_GetItem"). int `PyMapping_SetItemString`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, const char *\*key*, [PyObject](structures.xhtml#c.PyObject "PyObject") *\*v*)Map the string *key* to the value *v* in object *o*. Returns `-1` on failure. This is the equivalent of the Python statement `o[key] = v`. See also [`PyObject_SetItem()`](object.xhtml#c.PyObject_SetItem "PyObject_SetItem"). int `PyMapping_DelItem`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, [PyObject](structures.xhtml#c.PyObject "PyObject") *\*key*)Remove the mapping for the object *key* from the object *o*. Return `-1`on failure. This is equivalent to the Python statement `del o[key]`. This is an alias of [`PyObject_DelItem()`](object.xhtml#c.PyObject_DelItem "PyObject_DelItem"). int `PyMapping_DelItemString`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, const char *\*key*)Remove the mapping for the string *key* from the object *o*. Return `-1`on failure. This is equivalent to the Python statement `del o[key]`. int `PyMapping_HasKey`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, [PyObject](structures.xhtml#c.PyObject "PyObject") *\*key*)Return `1` if the mapping object has the key *key* and `0` otherwise. This is equivalent to the Python expression `key in o`. This function always succeeds. Note that exceptions which occur while calling the [`__getitem__()`](../reference/datamodel.xhtml#object.__getitem__ "object.__getitem__")method will get suppressed. To get error reporting use [`PyObject_GetItem()`](object.xhtml#c.PyObject_GetItem "PyObject_GetItem") instead. int `PyMapping_HasKeyString`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*, const char *\*key*)Return `1` if the mapping object has the key *key* and `0` otherwise. This is equivalent to the Python expression `key in o`. This function always succeeds. Note that exceptions which occur while calling the [`__getitem__()`](../reference/datamodel.xhtml#object.__getitem__ "object.__getitem__")method and creating a temporary string object will get suppressed. To get error reporting use [`PyMapping_GetItemString()`](#c.PyMapping_GetItemString "PyMapping_GetItemString") instead. [PyObject](structures.xhtml#c.PyObject "PyObject")\* `PyMapping_Keys`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)*Return value: New reference.*On success, return a list of the keys in object *o*. On failure, return *NULL*. 在 3.7 版更改: Previously, the function returned a list or a tuple. [PyObject](structures.xhtml#c.PyObject "PyObject")\* `PyMapping_Values`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)*Return value: New reference.*On success, return a list of the values in object *o*. On failure, return *NULL*. 在 3.7 版更改: Previously, the function returned a list or a tuple. [PyObject](structures.xhtml#c.PyObject "PyObject")\* `PyMapping_Items`([PyObject](structures.xhtml#c.PyObject "PyObject") *\*o*)*Return value: New reference.*On success, return a list of the items in object *o*, where each item is a tuple containing a key-value pair. On failure, return *NULL*. 在 3.7 版更改: Previously, the function returned a list or a tuple. ### 导航 - [索引](../genindex.xhtml "总目录") - [模块](../py-modindex.xhtml "Python 模块索引") | - [下一页](iter.xhtml "迭代器协议") | - [上一页](sequence.xhtml "Sequence Protocol") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) » - zh\_CN 3.7.3 [文档](../index.xhtml) » - [Python/C API 参考手册](index.xhtml) » - [抽象对象层](abstract.xhtml) » - $('.inline-search').show(0); | © [版权所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 软件基金会是一个非盈利组织。 [请捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [发现了问题](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 创建。