“Python Extend Vs Append” Kode Jawaban

cara menambahkan daftar daftar dalam python

list_of_Lists = [[1,2,3],['hello','world'],[True,False,None]]
list_of_Lists.append([1,'hello',True])
ouput = [[1, 2, 3], ['hello', 'world'], [True, False, None], [1, 'hello', True]]
friendly neighborhood googler

Perbedaan Antara Append () dan Extand () dalam Python

Difference between List append() and List extend() method
a =[1,2]
b= [3,4]

# append() method 
a.append(b)
print("Using append() method", a)

x =[1,2]
y= [3,4]


# extend() method 
x.extend(y)
print("Using extend() method", x)
Gorgeous Gazelle

Python Extend Vs Append

my_list = [23, 11, 42, 24523]

# append will add it as if you're adding a new list to it
my_list.append([34523, 76979])
print(my_list)

# extend will go over each item in the new source list and add each
# element as part of the target list (my_list)
my_list.extend([12, 99])
print(my_list)
Zealous Zebra

Jawaban yang mirip dengan “Python Extend Vs Append”

Pertanyaan yang mirip dengan “Python Extend Vs Append”

Lebih banyak jawaban terkait untuk “Python Extend Vs Append” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya