Metoda .append()
Metoda dodaje element na koniec listy.
Składnia:
list.append(item)
list.append(item)
list.append(item)
Parametry:
item – element dodawany do listy
Wartość zwracana:
None
Przykłady:
list1 = [1, 2, 3]
list1.append(1)
print(list1) # wynik --> [1, 2, 3, 1]
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.append(list2)
print(list1) # wynik --> [1, 2, 3, [4, 5, 6]]
list1 = [1, 2, 3]
list1.append('string')
print(list1) # wynik --> [1, 2, 3, 'string']
list1 = [1, 2, 3]
list1.append(1)
print(list1) # wynik --> [1, 2, 3, 1]
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.append(list2)
print(list1) # wynik --> [1, 2, 3, [4, 5, 6]]
list1 = [1, 2, 3]
list1.append('string')
print(list1) # wynik --> [1, 2, 3, 'string']
list1 = [1, 2, 3] list1.append(1) print(list1) # wynik --> [1, 2, 3, 1] list1 = [1, 2, 3] list2 = [4, 5, 6] list1.append(list2) print(list1) # wynik --> [1, 2, 3, [4, 5, 6]] list1 = [1, 2, 3] list1.append('string') print(list1) # wynik --> [1, 2, 3, 'string']