所有整数被实现成任意尺寸的 long 整数对象。
当出错时,大多数
PyLong_As*
API 返回
(return type)-1
不能区分数字。使用
PyErr_Occurred()
以消除歧义。
此子类型的
PyObject
表示 Python 整数对象。
此实例的
PyTypeObject
表示 Python 整数类型。这是相同对象作为
int
在 Python 层。
返回 True 若其自变量是
PyLongObject
或子类型的
PyLongObject
. This function always succeeds.
返回 True 若其自变量是
PyLongObject
,但不是子类型的
PyLongObject
. This function always succeeds.
返回新的
PyLongObject
对象从
v
,或
NULL
当故障时。
当前实现保持整数对象数组对于所有整数介于
-5
and
256
. When you create an int in that range you actually just get back a reference to the existing object.
返回新的
PyLongObject
对象从 C
unsigned
long
,或
NULL
当故障时。
返回新的
PyLongObject
对象从 C
Py_ssize_t
,或
NULL
当故障时。
返回新的
PyLongObject
对象从 C
size_t
,或
NULL
当故障时。
返回新的
PyLongObject
对象从 C
long
long
,或
NULL
当故障时。
返回新的
PyLongObject
对象从 C
unsigned
long
long
,或
NULL
当故障时。
返回新的
PyLongObject
对象从整数部分的
v
,或
NULL
当故障时。
返回新的
PyLongObject
基于字符串值
str
, which is interpreted according to the radix in
base
。若
pend
为非
NULL
,
*pend
will point to the first character in
str
which follows the representation of the number. If
base
is
0
,
str
is interpreted using the
整数文字
definition; in this case, leading zeros in a non-zero decimal number raises a
ValueError
。若
base
不是
0
, it must be between
2
and
36
, inclusive. Leading spaces and single underscores after a base specifier and between digits are ignored. If there are no digits,
ValueError
会被引发。
转换 Unicode 数字序列在字符串中 u to a Python integer value.
3.3 版新增。
创建 Python 整数从指针
p
. The pointer value can be retrieved from the resulting value using
PyLong_AsVoidPtr()
.
返回 C
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
引发
OverflowError
若值
obj
超出范围对于
long
.
返回
-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
若值
obj
大于
LONG_MAX
或小于
LONG_MIN
, set
*overflow
to
1
or
-1
, respectively, and return
-1
; otherwise, set
*overflow
to
0
. If any other exception occurs set
*overflow
to
0
并返回
-1
as usual.
返回
-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
long
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
引发
OverflowError
若值
obj
超出范围对于
long
long
.
返回
-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
long
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
若值
obj
大于
LLONG_MAX
或小于
LLONG_MIN
, set
*overflow
to
1
or
-1
, respectively, and return
-1
; otherwise, set
*overflow
to
0
. If any other exception occurs set
*overflow
to
0
并返回
-1
as usual.
返回
-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.2 版新增。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
Py_ssize_t
表示为
pylong
.
pylong
必须是实例化的
PyLongObject
.
引发
OverflowError
若值
pylong
超出范围对于
Py_ssize_t
.
返回
-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
返回 C
unsigned
long
表示为
pylong
.
pylong
必须是实例化的
PyLongObject
.
引发
OverflowError
若值
pylong
超出范围对于
unsigned
long
.
返回
(unsigned long)-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
返回 C
size_t
表示为
pylong
.
pylong
必须是实例化的
PyLongObject
.
引发
OverflowError
若值
pylong
超出范围对于
size_t
.
返回
(size_t)-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
返回 C
unsigned
long
long
表示为
pylong
.
pylong
必须是实例化的
PyLongObject
.
引发
OverflowError
若值
pylong
超出范围对于
unsigned
long
long
.
返回
(unsigned long long)-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.1 版改变:
A negative
pylong
现在引发
OverflowError
, not
TypeError
.
返回 C
unsigned
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
若值
obj
超出范围对于
unsigned
long
, return the reduction of that value modulo
ULONG_MAX + 1
.
返回
(unsigned long)-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
unsigned
long
long
表示为
obj
。若
obj
不是实例化的
PyLongObject
,首先调用其
__index__()
方法 (若存在) 以将它转换为
PyLongObject
.
若值
obj
超出范围对于
unsigned
long
long
, return the reduction of that value modulo
ULLONG_MAX + 1
.
返回
(unsigned long long)-1
当出错时。使用
PyErr_Occurred()
以消除歧义。
3.8 版改变:
使用
__index__()
if available.
3.10 版改变:
This function will no longer use
__int__()
.
返回 C
double
表示为
pylong
.
pylong
必须是实例化的
PyLongObject
.
引发
OverflowError
若值
pylong
超出范围对于
double
.
返回
-1.0
当出错时。使用
PyErr_Occurred()
以消除歧义。
转换 Python 整数
pylong
到 C
void
指针。若
pylong
无法转换,
OverflowError
will be raised. This is only assured to produce a usable
void
pointer for values created with
PyLong_FromVoidPtr()
.
返回
NULL
当出错时。使用
PyErr_Occurred()
以消除歧义。