mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-07-01 21:01:20 +08:00
fix(curriculum): update examples in lecture-working-with-loops-and-sequences (#64379)
This commit is contained in:
parent
2fee689ea5
commit
ff83419f2f
@ -56,22 +56,22 @@ print(numbers) # [1, 2, 2.5, 3, 4, 5]
|
||||
|
||||
The following code will insert the number `2.5` at index `2` in the `numbers` list.
|
||||
|
||||
If you want to remove an element from a list, you can use the `remove()` method. Here is an example of using the `remove()` method to remove a duplicate number from a `numbers` list:
|
||||
If you want to remove an element from a list, you can use the `remove()` method. The `remove()` method takes the value of the element to remove as an argument:
|
||||
|
||||
```py
|
||||
numbers = [1, 2, 3, 4, 5, 5]
|
||||
numbers.remove(5)
|
||||
numbers = [10, 20, 30, 40, 50, 50]
|
||||
numbers.remove(50)
|
||||
|
||||
print(numbers) # [1, 2, 3, 4, 5]
|
||||
print(numbers) # [10, 20, 30, 40, 50]
|
||||
```
|
||||
|
||||
It is important to note that this method will only remove the first occurrence of an item. Not all of them:
|
||||
|
||||
```py
|
||||
numbers = [1, 2, 3, 4, 5, 5, 5]
|
||||
numbers.remove(5)
|
||||
numbers = [10, 20, 30, 40, 50, 50, 50]
|
||||
numbers.remove(50)
|
||||
|
||||
print(numbers) # [1, 2, 3, 4, 5, 5]
|
||||
print(numbers) # [10, 20, 30, 40, 50, 50]
|
||||
```
|
||||
|
||||
To remove an element at a specific index in the list, you can use the `pop()` method like this:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user