The None 就业培训 下载中心 Wiki 联络 登录 注册 首页 Python 3.12.4 索引 模块 下一 上一 Python/C API 参考手册 具体对象层 整数对象 整数对象 ¶ 所有整数被实现成任意尺寸的 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 当故障时。 当前实现保持整数对象数组对于所有整数介于 -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 (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C unsigned long ,或 NULL 当故障时。 PyObject * PyLong_FromSsize_t ( Py_ssize_t v ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C Py_ssize_t ,或 NULL 当故障时。 PyObject * PyLong_FromSize_t ( size_t v ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C size_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 ,或 NULL on 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 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 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() and int.from_bytes() to convert a PyLongObject to/from an array of bytes in base 256 . You can call those from C using PyObject_CallMethod() . PyObject * PyLong_FromUnicodeObject ( PyObject * u , int base ) ¶ 返回值:新引用。 转换 Unicode 数字序列在字符串中 u to a Python integer value. Added in version 3.3. PyObject * PyLong_FromVoidPtr ( void * p ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 创建 Python 整数从指针 p . The pointer value can be retrieved from the resulting value using PyLong_AsVoidPtr() . long PyLong_AsLong ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long PyLong_AsLongAndOverflow ( PyObject * obj , int * overflow ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long long PyLong_AsLongLong ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long long PyLong_AsLongLongAndOverflow ( PyObject * obj , int * overflow ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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() 以消除歧义。 Added in version 3.2. 3.8 版改变: 使用 __index__() if available. 3.10 版改变: This function will no longer use __int__() . Py_ssize_t PyLong_AsSsize_t ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C Py_ssize_t 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 Py_ssize_t . 返回 -1 当出错时。使用 PyErr_Occurred() 以消除歧义。 unsigned long PyLong_AsUnsignedLong ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C unsigned long 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 unsigned long . 返回 (unsigned long)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。 size_t PyLong_AsSize_t ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C size_t 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 size_t . 返回 (size_t)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。 unsigned long long PyLong_AsUnsignedLongLong ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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 . unsigned long PyLong_AsUnsignedLongMask ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . unsigned long long PyLong_AsUnsignedLongLongMask ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . double PyLong_AsDouble ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C double 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 double . 返回 -1.0 当出错时。使用 PyErr_Occurred() 以消除歧义。 void * PyLong_AsVoidPtr ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 转换 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() 以消除歧义。 int PyUnstable_Long_IsCompact ( const PyLongObject * op ) ¶ 这为 Unstable API . It may change without warning in minor releases. Return 1 if op is compact, 0 otherwise. This function makes it possible for performance-critical code to implement a “fast path” for small integers. For compact values use PyUnstable_Long_CompactValue() ; for others fall back to a PyLong_As* function or calling int.to_bytes() . The speedup is expected to be negligible for most users. Exactly what values are considered compact is an implementation detail and is subject to change. Py_ssize_t PyUnstable_Long_CompactValue ( const PyLongObject * op ) ¶ 这为 Unstable API . It may change without warning in minor releases. 若 op is compact, as determined by PyUnstable_Long_IsCompact() , return its value. Otherwise, the return value is undefined. 上一话题 The None 对象 下一话题 布尔对象 本页 报告 Bug 展示源 快速搜索 键入搜索术语或模块、类、函数名称。 首页 Python 3.12.4 索引 模块 下一 上一 Python/C API 参考手册 具体对象层 整数对象
None 就业培训 下载中心 Wiki 联络 登录 注册 首页 Python 3.12.4 索引 模块 下一 上一 Python/C API 参考手册 具体对象层 整数对象 整数对象 ¶ 所有整数被实现成任意尺寸的 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 当故障时。 当前实现保持整数对象数组对于所有整数介于 -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 (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C unsigned long ,或 NULL 当故障时。 PyObject * PyLong_FromSsize_t ( Py_ssize_t v ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C Py_ssize_t ,或 NULL 当故障时。 PyObject * PyLong_FromSize_t ( size_t v ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 返回新的 PyLongObject 对象从 C size_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 ,或 NULL on 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 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 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() and int.from_bytes() to convert a PyLongObject to/from an array of bytes in base 256 . You can call those from C using PyObject_CallMethod() . PyObject * PyLong_FromUnicodeObject ( PyObject * u , int base ) ¶ 返回值:新引用。 转换 Unicode 数字序列在字符串中 u to a Python integer value. Added in version 3.3. PyObject * PyLong_FromVoidPtr ( void * p ) ¶ 返回值:新引用。 属于 稳定 ABI (应用程序二进制接口) . 创建 Python 整数从指针 p . The pointer value can be retrieved from the resulting value using PyLong_AsVoidPtr() . long PyLong_AsLong ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long PyLong_AsLongAndOverflow ( PyObject * obj , int * overflow ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long long PyLong_AsLongLong ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . long long PyLong_AsLongLongAndOverflow ( PyObject * obj , int * overflow ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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() 以消除歧义。 Added in version 3.2. 3.8 版改变: 使用 __index__() if available. 3.10 版改变: This function will no longer use __int__() . Py_ssize_t PyLong_AsSsize_t ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C Py_ssize_t 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 Py_ssize_t . 返回 -1 当出错时。使用 PyErr_Occurred() 以消除歧义。 unsigned long PyLong_AsUnsignedLong ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C unsigned long 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 unsigned long . 返回 (unsigned long)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。 size_t PyLong_AsSize_t ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C size_t 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 size_t . 返回 (size_t)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。 unsigned long long PyLong_AsUnsignedLongLong ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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 . unsigned long PyLong_AsUnsignedLongMask ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . unsigned long long PyLong_AsUnsignedLongLongMask ( PyObject * obj ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 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__() . double PyLong_AsDouble ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 返回 C double 表示为 pylong . pylong 必须是实例化的 PyLongObject . 引发 OverflowError 若值 pylong 超出范围对于 double . 返回 -1.0 当出错时。使用 PyErr_Occurred() 以消除歧义。 void * PyLong_AsVoidPtr ( PyObject * pylong ) ¶ 属于 稳定 ABI (应用程序二进制接口) . 转换 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() 以消除歧义。 int PyUnstable_Long_IsCompact ( const PyLongObject * op ) ¶ 这为 Unstable API . It may change without warning in minor releases. Return 1 if op is compact, 0 otherwise. This function makes it possible for performance-critical code to implement a “fast path” for small integers. For compact values use PyUnstable_Long_CompactValue() ; for others fall back to a PyLong_As* function or calling int.to_bytes() . The speedup is expected to be negligible for most users. Exactly what values are considered compact is an implementation detail and is subject to change. Py_ssize_t PyUnstable_Long_CompactValue ( const PyLongObject * op ) ¶ 这为 Unstable API . It may change without warning in minor releases. 若 op is compact, as determined by PyUnstable_Long_IsCompact() , return its value. Otherwise, the return value is undefined. 上一话题 The None 对象 下一话题 布尔对象 本页 报告 Bug 展示源 快速搜索 键入搜索术语或模块、类、函数名称。 首页 Python 3.12.4 索引 模块 下一 上一 Python/C API 参考手册 具体对象层 整数对象
所有整数被实现成任意尺寸的 long 整数对象。
当出错时,大多数 PyLong_As* API 返回 (return type)-1 不能区分数字。使用 PyErr_Occurred() 以消除歧义。
PyLong_As*
(return type)-1
PyErr_Occurred()
此子类型的 PyObject 表示 Python 整数对象。
PyObject
此实例的 PyTypeObject 表示 Python 整数类型。这是相同对象作为 int 在 Python 层。
PyTypeObject
int
返回 True 若其自变量是 PyLongObject 或子类型的 PyLongObject . This function always succeeds.
PyLongObject
返回 True 若其自变量是 PyLongObject ,但不是子类型的 PyLongObject . This function always succeeds.
返回新的 PyLongObject 对象从 v ,或 NULL 当故障时。
NULL
当前实现保持整数对象数组对于所有整数介于 -5 and 256 . When you create an int in that range you actually just get back a reference to the existing object.
-5
256
返回新的 PyLongObject 对象从 C unsigned long ,或 NULL 当故障时。
返回新的 PyLongObject 对象从 C Py_ssize_t ,或 NULL 当故障时。
Py_ssize_t
返回新的 PyLongObject 对象从 C size_t ,或 NULL 当故障时。
size_t
返回新的 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 ,或 NULL on 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 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 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 会被引发。
0
ValueError
2
36
另请参阅
Python methods int.to_bytes() and int.from_bytes() to convert a PyLongObject to/from an array of bytes in base 256 . You can call those from C using PyObject_CallMethod() .
int.to_bytes()
int.from_bytes()
PyObject_CallMethod()
转换 Unicode 数字序列在字符串中 u to a Python integer value.
Added in version 3.3.
创建 Python 整数从指针 p . The pointer value can be retrieved from the resulting value using PyLong_AsVoidPtr() .
PyLong_AsVoidPtr()
返回 C long 表示为 obj 。若 obj 不是实例化的 PyLongObject ,首先调用其 __index__() 方法 (若存在) 以将它转换为 PyLongObject .
__index__()
引发 OverflowError 若值 obj 超出范围对于 long .
OverflowError
返回 -1 当出错时。使用 PyErr_Occurred() 以消除歧义。
-1
3.8 版改变: 使用 __index__() if available.
3.10 版改变: This function will no longer use __int__() .
__int__()
若值 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.
LONG_MAX
LONG_MIN
1
返回 C long long 表示为 obj 。若 obj 不是实例化的 PyLongObject ,首先调用其 __index__() 方法 (若存在) 以将它转换为 PyLongObject .
引发 OverflowError 若值 obj 超出范围对于 long long .
若值 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.
LLONG_MAX
LLONG_MIN
Added in version 3.2.
返回 C Py_ssize_t 表示为 pylong . pylong 必须是实例化的 PyLongObject .
引发 OverflowError 若值 pylong 超出范围对于 Py_ssize_t .
返回 C unsigned long 表示为 pylong . pylong 必须是实例化的 PyLongObject .
引发 OverflowError 若值 pylong 超出范围对于 unsigned long .
返回 (unsigned long)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。
(unsigned long)-1
返回 C size_t 表示为 pylong . pylong 必须是实例化的 PyLongObject .
引发 OverflowError 若值 pylong 超出范围对于 size_t .
返回 (size_t)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。
(size_t)-1
返回 C unsigned long long 表示为 pylong . pylong 必须是实例化的 PyLongObject .
引发 OverflowError 若值 pylong 超出范围对于 unsigned long long .
返回 (unsigned long long)-1 当出错时。使用 PyErr_Occurred() 以消除歧义。
(unsigned long long)-1
3.1 版改变: A negative pylong 现在引发 OverflowError , not TypeError .
TypeError
返回 C unsigned long 表示为 obj 。若 obj 不是实例化的 PyLongObject ,首先调用其 __index__() 方法 (若存在) 以将它转换为 PyLongObject .
若值 obj 超出范围对于 unsigned long , return the reduction of that value modulo ULONG_MAX + 1 .
ULONG_MAX + 1
返回 C unsigned long long 表示为 obj 。若 obj 不是实例化的 PyLongObject ,首先调用其 __index__() 方法 (若存在) 以将它转换为 PyLongObject .
若值 obj 超出范围对于 unsigned long long , return the reduction of that value modulo ULLONG_MAX + 1 .
ULLONG_MAX + 1
返回 C double 表示为 pylong . pylong 必须是实例化的 PyLongObject .
引发 OverflowError 若值 pylong 超出范围对于 double .
返回 -1.0 当出错时。使用 PyErr_Occurred() 以消除歧义。
-1.0
转换 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() .
PyLong_FromVoidPtr()
返回 NULL 当出错时。使用 PyErr_Occurred() 以消除歧义。
Return 1 if op is compact, 0 otherwise.
This function makes it possible for performance-critical code to implement a “fast path” for small integers. For compact values use PyUnstable_Long_CompactValue() ; for others fall back to a PyLong_As* function or calling int.to_bytes() .
PyUnstable_Long_CompactValue()
calling
The speedup is expected to be negligible for most users.
Exactly what values are considered compact is an implementation detail and is subject to change.
若 op is compact, as determined by PyUnstable_Long_IsCompact() , return its value.
PyUnstable_Long_IsCompact()
Otherwise, the return value is undefined.
The None 对象
None
布尔对象
键入搜索术语或模块、类、函数名称。