Skip to content

Commit 44dad25

Browse files
authored
You cannot append to a list with []= in Python.
It would work in Ruby, but it just doesn't work in Python 2 or 3. Even []= immediately after end of list raises exception.
1 parent e7a404e commit 44dad25

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

python/lesson3/tutorial.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ positive and negative number for the index.
5959
### Modifying
6060

6161
Lists are *mutable*. This means that once created, you can change their
62-
contents and Python will just work with the updated list. You can add to a
62+
contents and Python will just work with the updated list. You can change a
6363
list a number of ways:
6464

6565
* Setting a value in the list explicitly with `[n]` where `n` is the index you
@@ -74,9 +74,9 @@ for a more complete reference:
7474
>>> places_to_visit
7575
['Mexico', 'Portugal', 'Kenya', 'Nepal', 'New Zealand']
7676

77-
>>> places_to_visit[5] = "Peru"
77+
>>> places_to_visit[1] = "Peru"
7878
>>> places_to_visit
79-
['Mexico', 'Portugal', 'Kenya', 'Nepal', 'New Zealand', 'Peru']
79+
['Mexico', 'Peru', 'Kenya', 'Nepal', 'New Zealand']
8080

8181
>>> places_to_visit.pop()
8282
'Peru'
@@ -89,8 +89,7 @@ for a more complete reference:
8989

9090
Try some of these out yourself:
9191

92-
* Try adding a country to a list with either the explicit indexing (`[n]`) or
93-
`.append()`. What happens if you give an index that's larger than the list?
92+
* Try adding a country to a list with `.append()`.
9493
* Take a look at the documentation and try out some of the other methods.
9594
`.count()` is a simple one, and `.reverse()` is handy to know.
9695

0 commit comments

Comments
 (0)