| <html devsite> |
| <head> |
| <meta name="project_path" value="/_project.yaml"> |
| <meta name="book_path" value="/versions/6.1.0/_book.yaml"> |
| </head> |
| <body> |
| |
| <h1 class="page-title" id="modules.list">list</h1> |
| |
| <!-- {% raw %} --> |
| |
| The built-in list type. Example list expressions:<br><pre class=language-python>x = [1, 2, 3]</pre>Accessing elements is possible using indexing (starts from <code>0</code>):<br><pre class=language-python>e = x[1] # e == 2</pre>Lists support the <code>+</code> operator to concatenate two lists. Example:<br><pre class=language-python>x = [1, 2] + [3, 4] # x == [1, 2, 3, 4] |
| x = ["a", "b"] |
| x += ["c"] # x == ["a", "b", "c"]</pre>Similar to strings, lists support slice operations:<pre class=language-python>['a', 'b', 'c', 'd'][1:3] # ['b', 'c'] |
| ['a', 'b', 'c', 'd'][::2] # ['a', 'c'] |
| ['a', 'b', 'c', 'd'][3:0:-1] # ['d', 'c', 'b']</pre>Lists are mutable, as in Python. |
| |
| <h2>Members</h2> |
| <ul> |
| <li> |
| <a href="#append">append</a> |
| </li> |
| <li> |
| <a href="#clear">clear</a> |
| </li> |
| <li> |
| <a href="#extend">extend</a> |
| </li> |
| <li> |
| <a href="#index">index</a> |
| </li> |
| <li> |
| <a href="#insert">insert</a> |
| </li> |
| <li> |
| <a href="#pop">pop</a> |
| </li> |
| <li> |
| <a href="#remove">remove</a> |
| </li> |
| </ul> |
| |
| <h2 id="append">append</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> list.append(item)</pre></p> |
| |
| Adds an item to the end of the list. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="append.item"> |
| <code>item</code> |
| </td> |
| <td> |
| required<br/> |
| Item to add at the end. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="clear">clear</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> list.clear()</pre></p> |
| |
| Removes all the elements of the list. |
| |
| |
| <h2 id="extend">extend</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> list.extend(items)</pre></p> |
| |
| Adds all items to the end of the list. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="extend.items"> |
| <code>items</code> |
| </td> |
| <td> |
| required<br/> |
| Items to add at the end. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="index">index</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="int.html">int</a> list.index(x, start=None, end=None)</pre></p> |
| |
| Returns the index in the list of the first item whose value is x. It is an error if there is no such item. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="index.x"> |
| <code>x</code> |
| </td> |
| <td> |
| required<br/> |
| The object to search. |
| </td> |
| </tr> |
| <tr> |
| <td id="index.start"> |
| <code>start</code> |
| </td> |
| <td> |
| <code><a class="anchor" href="int.html">int</a>; or <a class="anchor" href="globals.html#None">None</a></code>; |
| default = None<br/> |
| The start index of the list portion to inspect. |
| </td> |
| </tr> |
| <tr> |
| <td id="index.end"> |
| <code>end</code> |
| </td> |
| <td> |
| <code><a class="anchor" href="int.html">int</a>; or <a class="anchor" href="globals.html#None">None</a></code>; |
| default = None<br/> |
| The end index of the list portion to inspect. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="insert">insert</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> list.insert(index, item)</pre></p> |
| |
| Inserts an item at a given position. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="insert.index"> |
| <code>index</code> |
| </td> |
| <td> |
| required<br/> |
| The index of the given position. |
| </td> |
| </tr> |
| <tr> |
| <td id="insert.item"> |
| <code>item</code> |
| </td> |
| <td> |
| required<br/> |
| The item. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="pop">pop</h2> |
| <p><pre class="rule-signature">unknown list.pop(i=-1)</pre></p> |
| |
| Removes the item at the given position in the list, and returns it. If no <code>index</code> is specified, it removes and returns the last item in the list. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="pop.i"> |
| <code>i</code> |
| </td> |
| <td> |
| <code><a class="anchor" href="int.html">int</a>; or <a class="anchor" href="globals.html#None">None</a></code>; |
| default = -1<br/> |
| The index of the item. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <h2 id="remove">remove</h2> |
| <p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> list.remove(x)</pre></p> |
| |
| Removes the first item from the list whose value is x. It is an error if there is no such item. |
| |
| <!-- hide-from-toc is a class used by DevSite for the public Bazel site |
| (https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) --> |
| <h3 class="hide-from-toc">Parameters</h3> |
| <table class="table table-bordered table-condensed table-params"> |
| <colgroup> |
| <col class="col-param"> |
| <col class="param-description"> |
| </colgroup> |
| <thead> |
| <tr> |
| <th>Parameter</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td id="remove.x"> |
| <code>x</code> |
| </td> |
| <td> |
| required<br/> |
| The object to remove. |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| |
| </body> |
| </html> |
| |
| <!-- {% endraw %} --> |