mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
fixed error about list append() method [thanks G.P.]
This commit is contained in:
@@ -276,7 +276,7 @@ body{counter-reset:h1 2}
|
||||
<ol>
|
||||
<li>The <code>extend()</code> method takes a single argument, which is always a list, and adds each of the items of that list to <var>a_list</var>.
|
||||
<li>If you start with a list of three items and extend it with a list of another three items, you end up with a list of six items.
|
||||
<li>On the other hand, the <code>append()</code> method takes any number of arguments, each of which can be any datatype. Here, you’re calling the <code>append()</code> method with a single argument, a list of three items.
|
||||
<li>On the other hand, the <code>append()</code> method takes a single argument, which can be any datatype. Here, you’re calling the <code>append()</code> method with a list of three items.
|
||||
<li>If you start with a list of six items and append a list onto it, you end up with... a list of seven items. Why seven? Because the last item (which you just appended) <em>is itself a list</em>. Lists can contain any type of data, including other lists. That may be what you want, or it may not. But it’s what you asked for, and it’s what you got.
|
||||
</ol>
|
||||
<h3 id=searchinglists>Searching For Values In A List</h3>
|
||||
|
||||
Reference in New Issue
Block a user