Jak apend seznamu, seznam v pythonu

Příklady kódu

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

# Basic syntax:
your_list.append('element_to_append')

# Example usage:
your_list = ['a', 'b']
your_list.append('c')
print(your_list)
--> ['a', 'b', 'c']

# Note, .append() changes the list directly and doesn’t require an 
#	assignment operation. In fact, the following would produce an error:
your_list = your_list.append('c')
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)

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
..................................................................................................................