整數物件

All integers are implemented as "long" integer objects of arbitrary size.

On error, most PyLong_As* APIs return (return type)-1 which cannot be distinguished from a number. Use PyErr_Occurred() to disambiguate.

type PyLongObject
受限 API 的一部分 (做為一個不透明結構 (opaque struct)).

This subtype of PyObject represents a Python integer object.

PyTypeObject PyLong_Type
穩定 ABI 的一部分.

This instance of PyTypeObject represents the Python integer type. This is the same object as int in the Python layer.

int PyLong_Check(PyObject *p)

Return true if its argument is a PyLongObject or a subtype of PyLongObject. This function always succeeds.

int PyLong_CheckExact(PyObject *p)

Return true if its argument is a PyLongObject, but not a subtype of PyLongObject. This function always succeeds.

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

Return a new PyLongObject object from v, or NULL on failure.

CPython 實作細節: CPython keeps an array of integer objects for all integers between -5 and 256. When you create an int in that range you actually just get back a reference to the existing object.

PyObject *PyLong_FromUnsignedLong(unsigned long v)
回傳值:新的參照。穩定 ABI 的一部分.

Return a new PyLongObject object from a C unsigned long, or NULL on failure.

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

Return a new PyLongObject object from a C Py_ssize_t, or NULL on failure.

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

Return a new PyLongObject object from a C size_t, or NULL on failure.

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

Return a new PyLongObject object from a C long long, or NULL on failure.

PyObject *PyLong_FromInt32(int32_t value)
PyObject *PyLong_FromInt64(int64_t value)
穩定 ABI 的一部分 自 3.14 版本開始.

Return a new PyLongObject object from a signed C int32_t or int64_t, or NULL with an exception set on failure.

在 3.14 版被加入.

PyObject *PyLong_FromUnsignedLongLong(unsigned long long v)
回傳值:新的參照。穩定 ABI 的一部分.

Return a new PyLongObject object from a C unsigned long long, or NULL on failure.

PyObject *PyLong_FromUInt32(uint32_t value)
PyObject *PyLong_FromUInt64(uint64_t value)
穩定 ABI 的一部分 自 3.14 版本開始.

Return a new PyLongObject object from an unsigned C uint32_t or uint64_t, or NULL with an exception set on failure.

在 3.14 版被加入.

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

Return a new PyLongObject object from the integer part of v, or NULL on failure.

PyObject *PyLong_FromString(const char *str, char **pend, int base)