Skip to content

Commit

Permalink
Update example: Deleting a list while iterating over it
Browse files Browse the repository at this point in the history
* Corrects the explanation for `del` keyword.

Fixes satwikkansal/wtfpython#16
  • Loading branch information
tothetop430 committed Sep 4, 2017
1 parent 8da1c26 commit 8a9a96b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ Can you guess why the output is `[2, 4]`?


**Difference between `del`, `remove`, and `pop`:**
* `del var_name` just removes the binding of the `var_name` from the local or global namespace (That's why the `list_1` is unaffected).
* `remove` removes the first matching value, not a specific index, raises `ValueError` if the value is not found.
* `del` removes a specific index (That's why first `list_1` was unaffected), raises `IndexError` if an invalid index is specified.
* `pop` removes element at a specific index and returns it, raises `IndexError` if an invalid index is specified.

**Why the output is `[2, 4]`?**
Expand Down

0 comments on commit 8a9a96b

Please sign in to comment.