<!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>6.3 Sequence Protocol </TITLE>
<META NAME="description" CONTENT="6.3 Sequence Protocol ">
<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="next" HREF="mapping.html">
<LINK REL="previous" HREF="number.html">
<LINK REL="up" HREF="abstract.html">
<LINK REL="next" HREF="mapping.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="mapping.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="abstract.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="number.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="mapping.html">6.4 Mapping Protocol</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="abstract.html">6. Abstract Objects Layer</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="number.html">6.2 Number Protocol</A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION008300000000000000000"></A>
<BR>
6.3 Sequence Protocol 
</H1>

<P>
<dl><dt>int <b><a name="l2h-121"><tt class=cfunction>PySequence_Check</tt></a></b> (<var>PyObject *o</var>)
<dd>
Return <tt>1</tt> if the object provides sequence protocol, and <tt>0</tt>otherwise.  
This function always succeeds.
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-122"><tt class=cfunction>PySequence_Concat</tt></a></b> (<var>PyObject *o1, PyObject *o2</var>)
<dd>
Return the concatenation of <var>o1</var> and <var>o2</var> on success, and <tt>NULL</tt> on
failure.   This is the equivalent of the Python
expression "<tt class=samp><var>o1</var> + <var>o2</var></tt>".
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-123"><tt class=cfunction>PySequence_Repeat</tt></a></b> (<var>PyObject *o, int count</var>)
<dd>
Return the result of repeating sequence object <var>o</var> <var>count</var>
times, or <tt>NULL</tt> on failure.  This is the equivalent of the Python
expression "<tt class=samp><var>o</var> * <var>count</var></tt>".
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-124"><tt class=cfunction>PySequence_GetItem</tt></a></b> (<var>PyObject *o, int i</var>)
<dd>
Return the <var>i</var>th element of <var>o</var>, or <tt>NULL</tt> on failure. This
is the equivalent of the Python expression "<tt class=samp><var>o</var>[<var>i</var>]</tt>".
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-125"><tt class=cfunction>PySequence_GetSlice</tt></a></b> (<var>PyObject *o, int i1, int i2</var>)
<dd>
Return the slice of sequence object <var>o</var> between <var>i1</var> and
<var>i2</var>, or <tt>NULL</tt> on failure. This is the equivalent of the Python
expression "<tt class=samp><var>o</var>[<var>i1</var>:<var>i2</var>]</tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-126"><tt class=cfunction>PySequence_SetItem</tt></a></b> (<var>PyObject *o, int i, PyObject *v</var>)
<dd>
Assign object <var>v</var> to the <var>i</var>th element of <var>o</var>.
Returns <tt>-1</tt> on failure.  This is the equivalent of the Python
statement "<tt class=samp><var>o</var>[<var>i</var>] = <var>v</var></tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-127"><tt class=cfunction>PySequence_DelItem</tt></a></b> (<var>PyObject *o, int i</var>)
<dd>
Delete the <var>i</var>th element of object <var>v</var>.  Returns
<tt>-1</tt> on failure.  This is the equivalent of the Python
statement "<tt class=samp>del <var>o</var>[<var>i</var>]</tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-128"><tt class=cfunction>PySequence_SetSlice</tt></a></b> (<var>PyObject *o, int i1, int i2, PyObject *v</var>)
<dd>
Assign the sequence object <var>v</var> to the slice in sequence
object <var>o</var> from <var>i1</var> to <var>i2</var>.  This is the equivalent of
the Python statement "<tt class=samp><var>o</var>[<var>i1</var>:<var>i2</var>] = <var>v</var></tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-129"><tt class=cfunction>PySequence_DelSlice</tt></a></b> (<var>PyObject *o, int i1, int i2</var>)
<dd>
Delete the slice in sequence object <var>o</var> from <var>i1</var> to <var>i2</var>.
Returns <tt>-1</tt> on failure. This is the equivalent of the Python
statement "<tt class=samp>del <var>o</var>[<var>i1</var>:<var>i2</var>]</tt>".
</dl>

<P>
<dl><dt>PyObject* <b><a name="l2h-130"><tt class=cfunction>PySequence_Tuple</tt></a></b> (<var>PyObject *o</var>)
<dd>
Returns the <var>o</var> as a tuple on success, and <tt>NULL</tt> on failure.
This is equivalent to the Python expression <tt>tuple(<var>o</var>)</tt>.
</dl>

<P>
<dl><dt>int <b><a name="l2h-131"><tt class=cfunction>PySequence_Count</tt></a></b> (<var>PyObject *o, PyObject *value</var>)
<dd>
Return the number of occurrences of <var>value</var> in <var>o</var>, that is,
return the number of keys for which <tt><var>o</var>[<var>key</var>] ==
<var>value</var></tt>.  On failure, return <tt>-1</tt>.  This is equivalent to
the Python expression "<tt class=samp><var>o</var>.count(<var>value</var>)</tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-132"><tt class=cfunction>PySequence_In</tt></a></b> (<var>PyObject *o, PyObject *value</var>)
<dd>
Determine if <var>o</var> contains <var>value</var>.  If an item in <var>o</var> is
equal to <var>value</var>, return <tt>1</tt>, otherwise return <tt>0</tt>.  On
error, return <tt>-1</tt>.  This is equivalent to the Python expression
"<tt class=samp><var>value</var> in <var>o</var></tt>".
</dl>

<P>
<dl><dt>int <b><a name="l2h-133"><tt class=cfunction>PySequence_Index</tt></a></b> (<var>PyObject *o, PyObject *value</var>)
<dd>
Return the first index <var>i</var> for which <tt><var>o</var>[<var>i</var>] ==
<var>value</var></tt>.  On error, return <tt>-1</tt>.    This is equivalent to
the Python expression "<tt class=samp><var>o</var>.index(<var>value</var>)</tt>".
</dl>

<P>
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="mapping.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="abstract.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="number.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="mapping.html">6.4 Mapping Protocol</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="abstract.html">6. Abstract Objects Layer</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="number.html">6.2 Number Protocol</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>
