Python připojit v seznamu

Příklady kódu

72
0

N

#append to list
lst = [1, 2, 3]
something = 4
lst.append(something)
#lst is now [1, 2, 3, 4]
44
0

N


List = ["One", "value"]

List.append("to add") # "to add" can also be an int, a foat or whatever"

#List is now ["One", "value","to add"]

#Or

List2 = ["One", "value"]
# "to add" can be any type but IT MUST be in a list
List2 += ["to add"] # can be seen as List2 = List2 + ["to add"]

#List2 is now ["One", "value", "to add"]
16
0

N

my_list = ['a','b']  
my_list.append('c') 
print(my_list)      # ['a','b','c']

other_list = [1,2] 
my_list.append(other_list) 
print(my_list)      # ['a','b','c',[1,2]]

my_list.extend(other_list) 
print(my_list)      # ['a','b','c',[1,2],1,2]
9
0

N

list1 = ["hello"]
list1 = list1 + ["world"]
3
0

N

stuff = ["apple", "banana"]
stuff.append("carrot")
# Print to see if it worked
print(stuff)
# You can do it with a variable too
whatever = "pineapple"
stuff.append(whatever)
# Print it again
print(stuff)
2
0

N

lst=[1,2,3,4]
print(lst)

#prints [1,2,3,4]

lst.append(5)
print(lst)

#prints [1,2,3,4,5]

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................