Skip to content

Commit 3625e20

Browse files
committed
Merge pull request #401 from blossomica/master
Added list delete example and minor changes
2 parents 4b484c6 + 1b99fef commit 3625e20

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

en/python_introduction/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Easy, right? If you want to add something to your list, you can do this by typin
216216
>>> print(lottery)
217217
[59, 42, 30, 19, 12, 3, 199]
218218

219-
If you want to show only the first number, you can do this by using __indexes__. An index is the number that says where in a list an item occurs. Computer people like to start counting at 0, so the first object in your list is at index 0, the next one is at 1, and so on. Try this:
219+
If you want to show only the first number, you can do this by using __indexes__. An index is the number that says where in a list an item occurs. Programmers prefer to start counting at 0, so the first object in your list is at index 0, the next one is at 1, and so on. Try this:
220220

221221
>>> print(lottery[0])
222222
59
@@ -225,6 +225,18 @@ If you want to show only the first number, you can do this by using __indexes__.
225225

226226
As you can see, you can access different objects in your list by using the list's name and the object's index inside of square brackets.
227227

228+
To delete something from your list you will need to use __indexes__ as we learnt above and the __del__ statement (del is an abbreviation for delete). Let's try an example and reinforce what we learnt previously; we will be deleting the first number of our list.
229+
230+
>>> print(lottery)
231+
[59, 42, 30, 19, 12, 3, 199]
232+
>>> print(lottery[0])
233+
59
234+
>>> del lottery[0]
235+
>>> print(lottery)
236+
[42, 30, 19, 12, 3, 199]
237+
238+
That worked like a charm!
239+
228240
For extra fun, try some other indexes: 6, 7, 1000, -1, -6 or -1000. See if you can predict the result before trying the command. Do the results make sense?
229241

230242
You can find a list of all available list methods in this chapter of the Python documentation: https://docs.python.org/3/tutorial/datastructures.html
@@ -628,7 +640,7 @@ Congratulations! You just learned how to write functions! :)
628640

629641
This is the last part already. That was quick, right? :)
630642

631-
As we mentioned, programmers are lazy, they don't like to repeat themselves. Programming is all about automating things, so we don't want to greet every person by their name manually, right? That's where loops come in handy.
643+
Programmers don't like to repeat themselves. Programming is all about automating things, so we don't want to greet every person by their name manually, right? That's where loops come in handy.
632644

633645
Still remember lists? Let's do a list of girls:
634646

@@ -687,7 +699,7 @@ Which would print:
687699

688700
`range` is a function that creates a list of numbers following one after the other (these numbers are provided by you as parameters).
689701

690-
Note that the second of these two numbers is not included in the list that is output by Python (meaning `range(1, 6)` counts from 1 to 5, but does not include the number 6).
702+
Note that the second of these two numbers is not included in the list that is output by Python (meaning `range(1, 6)` counts from 1 to 5, but does not include the number 6). That is because "range" is half-open, and with that we mean it includes the first value, but not the last.
691703

692704
## Summary
693705

0 commit comments

Comments
 (0)