<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>7.2.3 List Objects </TITLE>
<META NAME="description" CONTENT="7.2.3 List Objects ">
<META NAME="keywords" CONTENT="api">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="api.css">
<LINK REL="previous" HREF="tupleObjects.html">
<LINK REL="up" HREF="sequenceObjects.html">
<LINK REL="next" HREF="mapObjects.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="mapObjects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="sequenceObjects.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="tupleObjects.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python/C API Reference Manual</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><img width=32 height=32 align=bottom border=0 alt=""
 src="../icons/blank.gif"></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="mapObjects.html">7.3 Mapping Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="sequenceObjects.html">7.2 Sequence Objects</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="tupleObjects.html">7.2.2 Tuple Objects</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION009230000000000000000"></A>
<BR>
7.2.3 List Objects 
</H2>

<P>
<dl><dt><b><a name="l2h-186"><tt class=ctype>PyListObject</tt></a></b>
<dd>
This subtype of <tt class=ctype>PyObject</tt> represents a Python list object.
</dl>

<P>
<dl><dt>PyTypeObject <b><a name="l2h-187"><tt class=cdata>PyList_Type</tt></a></b>
<dd>
This instance of <tt class=ctype>PyTypeObject</tt> represents the Python list type.
</dl>

<P>
<dl><dt>int <b><a name="l2h-188"><tt class=cfunction>PyList_Check</tt></a></b> (<var>PyObject *p</var>)
<dd>
Returns true if its argument is a <tt class=ctype>PyListObject</tt>.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-189"><tt class=cfunction>PyList_New</tt></a></b> (<var>int size</var>)
<dd>
Returns a new list of length <var>len</var> on success, and <tt>NULL</tt> on
failure.
</dl>

<P>
<dl><dt>int <b><a name="l2h-190"><tt class=cfunction>PyList_Size</tt></a></b> (<var>PyObject *list</var>)
<dd>
Returns the length of the list object in <var>list</var>.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-191"><tt class=cfunction>PyList_GetItem</tt></a></b> (<var>PyObject *list, int index</var>)
<dd>
Returns the object at position <var>pos</var> in the list pointed
to by <var>p</var>.  If <var>pos</var> is out of bounds, returns <tt>NULL</tt> and
sets an <tt class=exception>IndexError</tt> exception.  <b>Note:</b> this
function returns a ``borrowed'' reference.
</dl>

<P>
<dl><dt>int <b><a name="l2h-192"><tt class=cfunction>PyList_SetItem</tt></a></b> (<var>PyObject *list, int index,
                                       PyObject *item</var>)
<dd>
Sets the item at index <var>index</var> in list to <var>item</var>.
</dl>

<P>
<dl><dt>int <b><a name="l2h-193"><tt class=cfunction>PyList_Insert</tt></a></b> (<var>PyObject *list, int index,
                                      PyObject *item</var>)
<dd>
Inserts the item <var>item</var> into list <var>list</var> in front of index
<var>index</var>.  Returns 0 if successful; returns -1 and sets an
exception if unsuccessful.  Analogous to <tt>list.insert(index, item)</tt>.
</dl>

<P>
<dl><dt>int <b><a name="l2h-194"><tt class=cfunction>PyList_Append</tt></a></b> (<var>PyObject *list, PyObject *item</var>)
<dd>
Appends the object <var>item</var> at the end of list <var>list</var>.  Returns
0 if successful; returns -1 and sets an exception if unsuccessful.
Analogous to <tt>list.append(item)</tt>.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-195"><tt class=cfunction>PyList_GetSlice</tt></a></b> (<var>PyObject *list,
                                              int low, int high</var>)
<dd>
Returns a list of the objects in <var>list</var> containing the objects 
<i>between</i> <var>low</var> and <var>high</var>.  Returns NULL and sets an
exception if unsuccessful.
Analogous to <tt>list[low:high]</tt>.
</dl>

<P>
<dl><dt>int <b><a name="l2h-196"><tt class=cfunction>PyList_SetSlice</tt></a></b> (<var>PyObject *list,
                                        int low, int high,
                                        PyObject *itemlist</var>)
<dd>
Sets the slice of <var>list</var> between <var>low</var> and <var>high</var> to the contents
of <var>itemlist</var>.  Analogous to <tt>list[low:high]=itemlist</tt>.  Returns 0
on success, -1 on failure.
</dl>

<P>
<dl><dt>int <b><a name="l2h-197"><tt class=cfunction>PyList_Sort</tt></a></b> (<var>PyObject *list</var>)
<dd>
Sorts the items of <var>list</var> in place.  Returns 0 on success, -1 on failure.
</dl>

<P>
<dl><dt>int <b><a name="l2h-198"><tt class=cfunction>PyList_Reverse</tt></a></b> (<var>PyObject *list</var>)
<dd>
Reverses the items of <var>list</var> in place.  Returns 0 on success, -1 on failure.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-199"><tt class=cfunction>PyList_AsTuple</tt></a></b> (<var>PyObject *list</var>)
<dd>
Returns a new tuple object containing the contents of <var>list</var>.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-200"><tt class=cfunction>PyList_GET_ITEM</tt></a></b> (<var>PyObject *list, int i</var>)
<dd>
Macro form of <tt class=cfunction>PyList_GetItem()</tt> without error checking.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-201"><tt class=cfunction>PyList_SET_ITEM</tt></a></b> (<var>PyObject *list, int i,
                                              PyObject *o</var>)
<dd>
Macro form of <tt class=cfunction>PyList_SetItem()</tt> without error checking.
</dl>

<P>
<dl><dt>int <b><a name="l2h-202"><tt class=cfunction>PyList_GET_SIZE</tt></a></b> (<var>PyObject *list</var>)
<dd>
Macro form of <tt class=cfunction>PyList_GetSize()</tt> without error checking.
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="mapObjects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="sequenceObjects.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="tupleObjects.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python/C API Reference Manual</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><img width=32 height=32 align=bottom border=0 alt=""
 src="../icons/blank.gif"></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="mapObjects.html">7.3 Mapping Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="sequenceObjects.html">7.2 Sequence Objects</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="tupleObjects.html">7.2.2 Tuple Objects</A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
