Lista Pythona metoda pop()
Przykład
Usuń drugi element fruit
listy:
fruits = ['apple', 'banana', 'cherry']
fruits.pop(1)
Definicja i użycie
Metoda pop()
usuwa element w określonej pozycji.
Składnia
list.pop(pos)
Wartości parametrów
Parameter | Description |
---|---|
pos | Optional. A number specifying the position of the element you want to remove, default value is -1, which returns the last item |
Więcej przykładów
Przykład
Zwróć usunięty element:
fruits = ['apple', 'banana', 'cherry']
x =
fruits.pop(1)
Uwaga: Metoda pop()
zwraca usuniętą wartość.