数字协议 – 抽象对象层(Python教程)(参考资料)
数字协议
- PyObject *
PyNumber_Multiply( PyObject *o1,PyObject *o2) - Return value: New reference.
返回失败时o1和o2或NULL相乘的结果。这相当于Python表达式
o1 * o2.
- PyObject *
PyNumber_MatrixMultiply( PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1和o2或NULL onfailure的矩阵乘法结果。这相当于Python表达式
o1 @ o2.版本3.5中的新增.
- PyObject *
PyNumber_FloorDivide( PyObject *o1,PyObject *o2) - Return value: New reference.
退回o1的地板除以o2或NULL失败。这与整数的“经典”划分等价.
- PyObject*
PyNumber_TrueDivide( PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1除以o2或NULL的数学值的合理近似值。返回值是“近似值”,因为二进制浮点数是近似值;不可能代表基数2中的所有实数。当两个整数通过时,这个函数可以返回浮点值.
- PyObject*
PyNumber_Remainder( PyObject *o1,PyObject *o2) - Return value: New reference.
在失败时返回o1除以o2或NULL的剩余部分。这相当于Python表达式
o1 % o2.
- PyObject *
PyNumber_Divmod( PyObject *o1,PyObject *o2) - Return value: New reference.
看到内置函数
divmod()。失败时返回NULL。这相当于Python表达式divmod(o1, o2).
- PyObject *
PyNumber_Power( PyObject *o1,PyObject *o2,PyObject *o3) - Return value: New reference.
看到内置函数
pow()。失败时返回NULL。这是Python表达式pow(o1, o2, o3)的等价,其中o3是可选的。如果o3被忽略,则传递Py_None在它的位置(通过NULL为o3会导致非法的内存访问).
- PyObject *
PyNumber_Negative( PyObject *o) - Return value: New reference.
在成功时返回o的否定,或NULL失败了。这是Python表达式的等价
-o.
- PyObject *
PyNumber_Positive( PyObject *o) - Return value: New reference.
返回o on成功,还是NULL失败了。这相当于thePython表达式
+o.
- PyObject *
PyNumber_Absolute(的PyObject *o) - Return value: New reference.
返回o, 要么 NULL失败了。这相当于Python表达式
abs(o).
- PyObject *
PyNumber_Invert(的PyObject *o) - Return value: New reference.
返回o成功,或NULL失败了。这相当于Python表达式
~o.
- PyObject *
PyNumber_Lshift( PyObject *o1,PyObject *o2) - Return value: New reference.
返回成功时o1左移o2的结果,或NULLonFailure处。这相当于Python表达式
o1 << o2.
- PyObject *
PyNumber_Rshift( PyObject *o1,PyObject *o2) - Return value: New reference.
返回成功时o1右移o2的结果,或NULLonFailure处。这相当于Python表达式
o1 >> o2.
- PyObject *
PyNumber_And( PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1和o2成功的“按位和”NULL失败。这相当于Python表达式
o1 & o2.
- PyObject *
PyNumber_Xor( PyObject *o1,PyObject *o2) - Return value: New reference.
成功时o1返回o2的“按位异或”或NULLonFailure处。这相当于Python表达式
o1 ^ o2.
- PyObject *
PyNumber_Or( PyObject *o1,PyObject *o2) - Return value: New reference.
成功时返回o1和o2的“按位或”或NULL失败。这相当于Python表达式
o1 | o2.
- PyObject *
PyNumber_InPlaceAdd( PyObject *o1,PyObject *o2) - Return value: New reference.
- PyObject *
PyNumber_InPlaceSubtract( PyObject *o1,PyObject *o2) - Return value: New reference.
返回从失败时o2或o1减去NULL的结果。当in-place支持时,操作完成o1。这相当于Python语句
o1 -= o2.
- PyObject *
PyNumber_InPlaceMultiply( PyObject *o1,PyObject *o2) - Return value: New reference.
返回失败时o1和o2或NULL相乘的结果。当in-place支持时,操作完成o1。这相当于Python语句
o1 *= o2.
- PyObject *
PyNumber_InPlaceMatrixMultiply( PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1和o2或NULL onfailure的矩阵乘法结果。当in-place支持时,操作完成o1。这相当于Python语句
o1 @= o2.版本3.5.
- PyObject*
PyNumber_InPlaceFloorDivide( PyObject *o1,PyObject *o2) - Return value: New reference.
返回划分o1添加o2和NULL失败。当in-place支持时,操作完成o1。这相当于Python语句
o1 //= o2.
- PyObject *
PyNumber_InPlaceTrueDivide( PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1除以o2或NULL失败了。返回值是“近似值”,因为二进制浮点数是近似值;不可能代表基数2中的所有实数。当两个整数通过时,此函数可以返回浮点值。操作完成in-place什么时候 o1支持它
- PyObject *
PyNumber_InPlaceRemainder(的PyObject *o1,PyObject *o2) - Return value: New reference.
返回o1按o2, 要么 NULL失败了。操作完成in-place什么时候 o1支持它。这相当于Python语句
o1 %= o2.
- PyObject *
PyNumber_InPlacePower( PyObject *o1,PyObject *o2,PyObject *o3) - Return value: New reference.
查看内置函数
pow()。返回NULL失败了。当in-place支持时,操作完成o1。当o3是o1 **= o2时,这相当于Python语句Py_None,否则就是pow(o1, o2, o3)的原位变体。如果o3是被忽略的,通过Py_None在它的位置(通过NULL为o3会造成非法的记忆访问).
- PyObject *
PyNumber_InPlaceLshift(的PyObject *o1,PyObject *o2) - Return value: New reference.
返回成功时o1左移o2的结果,或NULL onfailure。当in-place支持时,操作完成o1。这是Python声明的等价
o1 <<= o2.
- PyObject *
PyNumber_InPlaceRshift(的PyObject *o1,PyObject *o2) - Return value: New reference.
返回右移的结果o1按o2成功,或NULLonFailure处。操作完成in-place什么时候 o1支持它。这是Python语句的等价
o1 >>= o2.
- PyObject *
PyNumber_InPlaceAnd( PyObject *o1,PyObject *o2) - Return value: New reference.
成功时返回o1和o2的“按位和”和NULL失败了。当in-place在成功时o1支持它。这相当于Python语句
o1 &= o2.
- PyObject *
PyNumber_InPlaceXor( PyObject *o1,PyObject *o2) - Return value: New reference.
成功时返回o1按o2的“按位异或”,或NULL onfailure。当in-place支持时,操作完成o1。这是Python语句的等价
o1 ^= o2.
- PyObject *
PyNumber_InPlaceOr( PyObject *o1,PyObject *o2) - Return value: New reference.
成功时返回o1和o2的“按位或”,或者失败时返回NULL。当in-place支持时,操作完成o1。这相当于Python语句
o1 |= o2.
- PyObject *
PyNumber_Long( PyObject *o) - Return value: New reference.
返回o成功时转换为整数对象,或NULL onfailure。这相当于Python表达式
int(o).
- PyObject *
PyNumber_Float( PyObject *o) - Return value: New reference.
返回o成功时转换为float对象,或者失败时转换为NULL。这相当于Python表达式
float(o).
- PyObject *
PyNumber_Index( PyObject *o) - Return value: New reference.
返回o转换为Python int或NULL时失败引起
TypeError异常,操作完成
- PyObject*
PyNumber_ToBase( PyObject *n,int base) - Return value: New reference.
返回n转换为base base的整数作为字符串。base参数必须是2个,8个,10个或16个中的一个。对于基数2,8或16,其中的字符串前缀为
"0b","0o",或"0x"。如果n不是Python int,则用PyNumber_Index()转换
Py_ssize_t PyNumber_AsSsize_t( PyObject *o,PyObject *exc)- 返回o如果o可以解释为整数,则转换为Py_ssize_t值。如果调用失败,则会引发异常并返回
-1如果o可以转换为Python int但是转换为Py_ssize_t值的尝试会引发
OverflowError,然后exc参数是将要引发的异常类型(通常是IndexError要么OverflowError)。如果exc是NULL,则清除异常并将值剪切为PY_SSIZE_T_MIN以获得负整数或PY_SSIZE_T_MAX一个正整数.
- int
PyIndex_Check( PyObject *o) - 返回
1如果o是一个索引整数(填充了tp_as_number结构的nb_index槽)和0否则。这个函数总是成功的.
评论被关闭。