“Daftar Python diperpanjang” Kode Jawaban

Perluas daftar Pyton

animals = ['dog', 'cat']

# tuple
mammals = ('tiger', 'elephant')

animals.extend(mammals)

print('Updated list:', animals)

# dictionary
birds = {'owl': 1, 'parrot': 2}

animals.extend(birds)

print('Updated list:', animals)

#Updated list: ['dog', 'cat', 'tiger', 'elephant']
#Updated list: ['dog', 'cat', 'tiger', 'elephant', 'owl', 'parrot']
David Cao

Daftar Python diperpanjang

# testing
a = [1, 2]
b = [3, 4]
a.extend(b)
print(a) # [1, 2, 3, 4]
Kyle Reese

Daftar 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

Daftar Python ()

Python Program to extend the list
# Programming list
programming_list = ['C','C#','Python','Java']

frontend_programming =['CSS','HTML','JavaScript']

# add the frontend_progamming list into the existing list
programming_list.extend(frontend_programming)

# Note that iterable element is added to the end of the list
print('The new extended list is :', programming_list)
Gorgeous Gazelle

Daftar Python diperpanjang

# My List
my_list = ['geeks', 'for', 'geeks']
  
# My Tuple
my_tuple = ('DSA', 'Java')
  
# My Set
my_set = {'Flutter', 'Android'}
  
# Append tuple to the list
my_list.extend(my_tuple)
  
print(my_list)
  
# Append set to the list
my_list.extend(my_set)
  
print(my_list)
['geeks', 'for', 'geeks', 'DSA', 'Java']
['geeks', 'for', 'geeks', 'DSA', 'Java', 'Android', 'Flutter']
David Cao

Jawaban yang mirip dengan “Daftar Python diperpanjang”

Pertanyaan yang mirip dengan “Daftar Python diperpanjang”

Lebih banyak jawaban terkait untuk “Daftar Python diperpanjang” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya