<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"api.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"api.html" title='Python/C API Reference Manual'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"sequence.html" />
<link rel=
"prev" href=
"object.html" />
<link rel=
"parent" href=
"abstract.html" />
<link rel=
"next" href=
"sequence.html" />
<meta name='aesop' content='information'
/>
<title>6.2 Number Protocol
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.1 Object Protocol"
href=
"object.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6. Abstract Objects Layer"
href=
"abstract.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.3 Sequence Protocol"
href=
"sequence.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python/C API Reference Manual
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"object.html">6.1 Object Protocol
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"abstract.html">6. Abstract Objects Layer
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"sequence.html">6.3 Sequence Protocol
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION008200000000000000000"></A><A NAME=
"number"></A>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
264' xml:id='l2h-
264'
class=
"cfunction">PyNumber_Check
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
Returns
<code>1</code> if the object
<var>o
</var> provides numeric protocols,
and false otherwise. This function always succeeds.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
265' xml:id='l2h-
265'
class=
"cfunction">PyNumber_Add
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of adding
<var>o1
</var> and
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on
failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> + <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
266' xml:id='l2h-
266'
class=
"cfunction">PyNumber_Subtract
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of subtracting
<var>o2
</var> from
<var>o1
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> - <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
267' xml:id='l2h-
267'
class=
"cfunction">PyNumber_Multiply
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of multiplying
<var>o1
</var> and
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> * <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
268' xml:id='l2h-
268'
class=
"cfunction">PyNumber_Divide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of dividing
<var>o1
</var> by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on
failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> / <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
269' xml:id='l2h-
269'
class=
"cfunction">PyNumber_FloorDivide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Return the floor of
<var>o1
</var> divided by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on
failure. This is equivalent to the ``classic'' division of
<span class=
"versionnote">New in version
2.2.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
270' xml:id='l2h-
270'
class=
"cfunction">PyNumber_TrueDivide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Return a reasonable approximation for the mathematical value of
<var>o1
</var> divided by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on failure. The return
value is ``approximate'' because binary floating point numbers are
approximate; it is not possible to represent all real numbers in
base two. This function can return a floating point value when
<span class=
"versionnote">New in version
2.2.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
271' xml:id='l2h-
271'
class=
"cfunction">PyNumber_Remainder
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the remainder of dividing
<var>o1
</var> by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> % <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
272' xml:id='l2h-
272'
class=
"cfunction">PyNumber_Divmod
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
See the built-in function
<tt class=
"function">divmod()
</tt><a id='l2h-
273' xml:id='l2h-
273'
></a>.
Returns
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python
expression
"<tt class="samp
">divmod(<var>o1</var>, <var>o2</var>)</tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
274' xml:id='l2h-
274'
class=
"cfunction">PyNumber_Power
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>, PyObject *
<var>o3
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
See the built-in function
<tt class=
"function">pow()
</tt><a id='l2h-
275' xml:id='l2h-
275'
></a>.
Returns
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python
expression
"<tt class="samp
">pow(<var>o1</var>, <var>o2</var>, <var>o3</var>)</tt>", where
<var>o3
</var>
is optional. If
<var>o3
</var> is to be ignored, pass
<tt class=
"cdata">Py_None
</tt> in
its place (passing
<tt class=
"constant">NULL
</tt> for
<var>o3
</var> would cause an illegal
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
276' xml:id='l2h-
276'
class=
"cfunction">PyNumber_Negative
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the negation of
<var>o
</var> on success, or
<tt class=
"constant">NULL
</tt> on failure.
This is the equivalent of the Python expression
"<tt class="samp
">-<var>o</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
277' xml:id='l2h-
277'
class=
"cfunction">PyNumber_Positive
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns
<var>o
</var> on success, or
<tt class=
"constant">NULL
</tt> on failure. This is the
equivalent of the Python expression
"<tt class="samp
">+<var>o</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
278' xml:id='l2h-
278'
class=
"cfunction">PyNumber_Absolute
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the absolute value of
<var>o
</var>, or
<tt class=
"constant">NULL
</tt> on failure. This
is the equivalent of the Python expression
"<tt class="samp
">abs(<var>o</var>)</tt>".
<a id='l2h-
279' xml:id='l2h-
279'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
280' xml:id='l2h-
280'
class=
"cfunction">PyNumber_Invert
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the bitwise negation of
<var>o
</var> on success, or
<tt class=
"constant">NULL
</tt> on
failure. This is the equivalent of the Python expression
"<tt class="samp
">~<var>o</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
281' xml:id='l2h-
281'
class=
"cfunction">PyNumber_Lshift
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of left shifting
<var>o1
</var> by
<var>o2
</var> on success,
or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python
expression
"<tt class="samp
"><var>o1</var> <<code><</code> <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
282' xml:id='l2h-
282'
class=
"cfunction">PyNumber_Rshift
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of right shifting
<var>o1
</var> by
<var>o2
</var> on
success, or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the
Python expression
"<tt class="samp
"><var>o1</var> ><code>></code> <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
283' xml:id='l2h-
283'
class=
"cfunction">PyNumber_And
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise and'' of
<var>o1
</var> and
<var>o2
</var> on success and
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> & <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
284' xml:id='l2h-
284'
class=
"cfunction">PyNumber_Xor
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise exclusive or'' of
<var>o1
</var> by
<var>o2
</var> on
success, or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the
Python expression
"<tt class="samp
"><var>o1</var> ^ <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
285' xml:id='l2h-
285'
class=
"cfunction">PyNumber_Or
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise or'' of
<var>o1
</var> and
<var>o2
</var> on success, or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python expression
"<tt class="samp
"><var>o1</var> | <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
286' xml:id='l2h-
286'
class=
"cfunction">PyNumber_InPlaceAdd
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of adding
<var>o1
</var> and
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on
failure. The operation is done
<em>in-place
</em> when
<var>o1
</var>
supports it. This is the equivalent of the Python statement
"<tt class="samp
"><var>o1</var> += <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
287' xml:id='l2h-
287'
class=
"cfunction">PyNumber_InPlaceSubtract
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of subtracting
<var>o2
</var> from
<var>o1
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var>
supports it. This is the equivalent of the Python statement
"<tt class="samp
"><var>o1</var> -= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
288' xml:id='l2h-
288'
class=
"cfunction">PyNumber_InPlaceMultiply
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of multiplying
<var>o1
</var> and
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var>
supports it. This is the equivalent of the Python statement
"<tt class="samp
"><var>o1</var> *= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
289' xml:id='l2h-
289'
class=
"cfunction">PyNumber_InPlaceDivide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of dividing
<var>o1
</var> by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on
failure. The operation is done
<em>in-place
</em> when
<var>o1
</var>
supports it. This is the equivalent of the Python statement
"<tt class="samp
"><var>o1</var> /= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
290' xml:id='l2h-
290'
class=
"cfunction">PyNumber_InPlaceFloorDivide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the mathematical floor of dividing
<var>o1
</var> by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent of the Python
statement
"<tt class="samp
"><var>o1</var> //= <var>o2</var></tt>".
<span class=
"versionnote">New in version
2.2.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
291' xml:id='l2h-
291'
class=
"cfunction">PyNumber_InPlaceTrueDivide
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Return a reasonable approximation for the mathematical value of
<var>o1
</var> divided by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt> on failure. The return
value is ``approximate'' because binary floating point numbers are
approximate; it is not possible to represent all real numbers in
base two. This function can return a floating point value when
passed two integers. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it.
<span class=
"versionnote">New in version
2.2.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
292' xml:id='l2h-
292'
class=
"cfunction">PyNumber_InPlaceRemainder
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the remainder of dividing
<var>o1
</var> by
<var>o2
</var>, or
<tt class=
"constant">NULL
</tt>
on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var>
supports it. This is the equivalent of the Python statement
"<tt class="samp
"><var>o1</var> %= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
293' xml:id='l2h-
293'
class=
"cfunction">PyNumber_InPlacePower
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>, PyObject *
<var>o3
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
See the built-in function
<tt class=
"function">pow()
</tt>.
<a id='l2h-
294' xml:id='l2h-
294'
></a> Returns
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em>
when
<var>o1
</var> supports it. This is the equivalent of the Python
statement
"<tt class="samp
"><var>o1</var> **= <var>o2</var></tt>" when o3 is
<tt class=
"cdata">Py_None
</tt>,
or an in-place variant of
"<tt class="samp
">pow(<var>o1</var>, <var>o2</var>, <var>o3</var>)</tt>" otherwise. If
<var>o3
</var> is to be ignored, pass
<tt class=
"cdata">Py_None
</tt> in its
place (passing
<tt class=
"constant">NULL
</tt> for
<var>o3
</var> would cause an illegal memory
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
295' xml:id='l2h-
295'
class=
"cfunction">PyNumber_InPlaceLshift
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of left shifting
<var>o1
</var> by
<var>o2
</var> on success,
or
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent of the Python
statement
"<tt class="samp
"><var>o1</var> <<code><=</code> <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
296' xml:id='l2h-
296'
class=
"cfunction">PyNumber_InPlaceRshift
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>,
PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the result of right shifting
<var>o1
</var> by
<var>o2
</var> on
success, or
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent
of the Python statement
"<tt class="samp
"><var>o1</var> ><code>>=</code> <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
297' xml:id='l2h-
297'
class=
"cfunction">PyNumber_InPlaceAnd
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise and'' of
<var>o1
</var> and
<var>o2
</var> on success and
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent of the Python
statement
"<tt class="samp
"><var>o1</var> &= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
298' xml:id='l2h-
298'
class=
"cfunction">PyNumber_InPlaceXor
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise exclusive or'' of
<var>o1
</var> by
<var>o2
</var> on
success, or
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent
of the Python statement
"<tt class="samp
"><var>o1</var> ^= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
299' xml:id='l2h-
299'
class=
"cfunction">PyNumber_InPlaceOr
</tt></b>(
</nobr></td><td>PyObject *
<var>o1
</var>, PyObject *
<var>o2
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the ``bitwise or'' of
<var>o1
</var> and
<var>o2
</var> on success, or
<tt class=
"constant">NULL
</tt> on failure. The operation is done
<em>in-place
</em> when
<var>o1
</var> supports it. This is the equivalent of the Python
statement
"<tt class="samp
"><var>o1</var> |= <var>o2</var></tt>".
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>int
<b><tt id='l2h-
300' xml:id='l2h-
300'
class=
"cfunction">PyNumber_Coerce
</tt></b>(
</nobr></td><td>PyObject **
<var>p1
</var>, PyObject **
<var>p2
</var>)
</td></tr></table></dt>
This function takes the addresses of two variables of type
<tt class=
"ctype">PyObject*
</tt>. If the objects pointed to by
<code>*
<var>p1
</var></code>
and
<code>*
<var>p2
</var></code> have the same type, increment their reference
count and return
<code>0</code> (success). If the objects can be converted
to a common numeric type, replace
<code>*p1
</code> and
<code>*p2
</code> by their
converted value (with 'new' reference counts), and return
<code>0</code>.
If no conversion is possible, or if some other error occurs, return
<code>-
1</code> (failure) and don't increment the reference counts. The
call
<code>PyNumber_Coerce(
&o1,
&o2)
</code> is equivalent to the Python
statement
"<tt class="samp
"><var>o1</var>, <var>o2</var> = coerce(<var>o1</var>, <var>o2</var>)</tt>".
<a id='l2h-
301' xml:id='l2h-
301'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
302' xml:id='l2h-
302'
class=
"cfunction">PyNumber_Int
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the
<var>o
</var> converted to an integer object on success, or
<tt class=
"constant">NULL
</tt> on failure. If the argument is outside the integer range
a long object will be returned instead. This is the equivalent
of the Python expression
"<tt class="samp
">int(<var>o</var>)</tt>".
<a id='l2h-
303' xml:id='l2h-
303'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
304' xml:id='l2h-
304'
class=
"cfunction">PyNumber_Long
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the
<var>o
</var> converted to a long integer object on success,
or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python
expression
"<tt class="samp
">long(<var>o</var>)</tt>".
<a id='l2h-
305' xml:id='l2h-
305'
></a></dd></dl>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline"><td><nobr>PyObject*
<b><tt id='l2h-
306' xml:id='l2h-
306'
class=
"cfunction">PyNumber_Float
</tt></b>(
</nobr></td><td>PyObject *
<var>o
</var>)
</td></tr></table></dt>
<div class=
"refcount-info">
<span class=
"label">Return value:
</span>
<span class=
"value">New reference.
</span>
Returns the
<var>o
</var> converted to a float object on success, or
<tt class=
"constant">NULL
</tt> on failure. This is the equivalent of the Python expression
"<tt class="samp
">float(<var>o</var>)</tt>".
<a id='l2h-
307' xml:id='l2h-
307'
></a></dd></dl>
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.1 Object Protocol"
href=
"object.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6. Abstract Objects Layer"
href=
"abstract.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.3 Sequence Protocol"
href=
"sequence.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python/C API Reference Manual
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"object.html">6.1 Object Protocol
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"abstract.html">6. Abstract Objects Layer
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"sequence.html">6.3 Sequence Protocol
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.