字典物件

type PyDictObject

PyObject 子型別代表一個 Python 字典物件。

PyTypeObject PyDict_Type
穩定 ABI 的一部分.

PyTypeObject 實例代表一個 Python 字典型別。此與 Python 層中的 dict 為同一個物件。

int PyDict_Check(PyObject *p)
Thread safety: Atomic.

p 是一個字典物件或字典的子型別實例則會回傳 true。此函式每次都會執行成功。

int PyDict_CheckExact(PyObject *p)
Thread safety: Atomic.

p 是一個字典物件但並不是一個字典子型別的實例,則回傳 true。此函式每次都會執行成功。

PyObject *PyDict_New()
回傳值:新的參照。穩定 ABI 的一部分. Thread safety: Atomic.

回傳一個新的空字典,或在失敗時回傳 NULL

PyObject *PyDictProxy_New(PyObject *mapping)
回傳值:新的參照。穩定 ABI 的一部分.

Return a types.MappingProxyType object for a mapping which enforces read-only behavior. This is normally used to create a view to prevent modification of the dictionary for non-dynamic class types.

PyTypeObject PyDictProxy_Type
穩定 ABI 的一部分.

The type object for mapping proxy objects created by PyDictProxy_New() and for the read-only __dict__ attribute of many built-in types. A PyDictProxy_Type instance provides a dynamic, read-only view of an underlying dictionary: changes to the underlying dictionary are reflected in the proxy, but the proxy itself does not support mutation operations. This corresponds to types.MappingProxyType in Python.

void PyDict_Clear(PyObject *p)
穩定 ABI 的一部分. Thread safety: Atomic.

清空現有字典中的所有鍵值對。

int PyDict_Contains(PyObject *p, PyObject *key)
穩定 ABI 的一部分. Thread safety: Safe for concurrent use on the same object.

Determine if dictionary p contains key. If an item in p matches key, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression key in p.

備註

The operation is atomic on free threading when key is str, int, float, bool or bytes.

int PyDict_ContainsString(PyObject *p, const char *key)
Thread safety: Atomic.

This is the same as PyDict_Contains(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

在 3.13 版被加入.

PyObject *PyDict_Copy(PyObject *p)
回傳值:新的參照。穩定 ABI 的一部分. Thread safety: Atomic.

回傳一個新的字典,包含與 p 相同的鍵值對。

int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
穩定 ABI 的一部分. Thread safety: Safe for concurrent use on the same object.

Insert val into the dictionary p with a key of key. key must be hashable; if it isn't, TypeError will be raised. Return 0 on success or -1 on failure. This function does not steal a reference to val.

備註

The operation is atomic on free threading when key is str, int, float, bool or bytes.

int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
穩定 ABI 的一部分. Thread safety: Atomic.

This is the same as PyDict_SetItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

int PyDict_DelItem(PyObject *p, PyObject *key)
穩定 ABI 的一部分. Thread safety: Safe for concurrent use on the same object.

Remove the entry in dictionary p with key key. key must be hashable; if it isn't, TypeError is raised. If key is not in the dictionary,