mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-11-25 20:44:24 +01:00
Update example: Deleting a list while iterating over it
* Corrects the explanation for `del` keyword. Fixes https://github.com/satwikkansal/wtfpython/issues/16
This commit is contained in:
parent
d4a60ac9d0
commit
7e93e0cb91
2
README.md
vendored
2
README.md
vendored
@ -362,8 +362,8 @@ Can you guess why the output is `[2, 4]`?
|
|||||||
|
|
||||||
|
|
||||||
**Difference between `del`, `remove`, and `pop`:**
|
**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.
|
* `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.
|
* `pop` removes element at a specific index and returns it, raises `IndexError` if an invalid index is specified.
|
||||||
|
|
||||||
**Why the output is `[2, 4]`?**
|
**Why the output is `[2, 4]`?**
|
||||||
|
Loading…
Reference in New Issue
Block a user