整数对象 ¶
所有整数被实现成任意尺寸的 long 整数对象。
当出错时,大多数
PyLong_As*
API 返回
(return type)-1
不能区分数字。使用
PyErr_Occurred()
以消除歧义。
-
type
PyLongObject
¶
-
属于
Limited API
(as an opaque struct).
此子类型的
PyObject表示 Python 整数对象。
-
PyTypeObject
PyLong_Type
¶
-
属于
稳定 ABI (应用程序二进制接口)
.
此实例的
PyTypeObject表示 Python 整数类型。这是相同对象作为int在 Python 层。
-
int
PyLong_Check
(
PyObject
*
p
)
¶
-
返回 True 若其自变量是
PyLongObject或子类型的PyLongObject. This function always succeeds.
-
int
PyLong_CheckExact
(
PyObject
*
p
)
¶
-
返回 True 若其自变量是
PyLongObject,但不是子类型的PyLongObject. This function always succeeds.
-
PyObject
*
PyLong_FromLong
(
long
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从 v ,或NULL当故障时。当前实现保持整数对象数组对于所有整数介于
-5and256. 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 (应用程序二进制接口)
.
返回新的
PyLongObject对象从 C unsigned long ,或NULL当故障时。
-
PyObject
*
PyLong_FromSsize_t
(
Py_ssize_t
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从 CPy_ssize_t,或NULL当故障时。
-
PyObject
*
PyLong_FromSize_t
(
size_t
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从 Csize_t,或NULL当故障时。
-
PyObject
*
PyLong_FromLongLong
(
long
long
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从 C long long ,或NULL当故障时。
-
PyObject
*
PyLong_FromUnsignedLongLong
(
unsigned
long
long
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从 C unsigned long long ,或NULL当故障时。
-
PyObject
*
PyLong_FromDouble
(
double
v
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject对象从整数部分的 v ,或NULL当故障时。
-
PyObject
*
PyLong_FromString
(
const
char
*
str
,
char
*
*
pend
,
int
base
)
¶
-
返回值:新引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回新的
PyLongObject基于字符串值 str , which is interpreted according to the radix in base ,或NULLon failure. If pend 为非NULL, *pend will point to the end of str on success or to the first character that could not be processed on error. If base is0, str is interpreted using the 整数文字 definition; in this case, leading zeros in a non-zero decimal number raises aValueError。若 base 不是0, it must be between2and36, inclusive. Leading and trailing whitespace and single underscores after a base specifier and between digits are ignored. If there are no digits or str is not NULL-terminated following the digits and trailing whitespace,ValueError会被引发。另请参阅
Python methods
int.to_bytes()andint.from_bytes()to convert aPyLongObjectto/from an array of bytes in base256. You can call those from C usingPyObject_CallMethod().