Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python extend list

# Basic syntax:
first_list.append(second_list) # Append adds the second_list as an
#	element to the first_list
first_list.extend(second_list) # Extend combines the elements of the 
#	first_list and the second_list

# Note, both append and extend modify the first_list in place

# Example usage for append:
first_list = [1, 2, 3, 4, 5]
second_list = [6, 7, 8, 9]
first_list.append(second_list)
print(first_list)
--> [1, 2, 3, 4, 5, [6, 7, 8, 9]]

# Example usage for extend:
first_list = [1, 2, 3, 4, 5]
second_list = [6, 7, 8, 9]
first_list.extend(second_list)
print(first_list)
--> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Comment

extend a list python

#adding two or more elements in a list
list1 = [1,2,3,4,5]
list1.extend([6,7,8])
print(list1)
#output = [1, 2, 3 ,4 ,5, 6, 7, 8]
Comment

Python List extend()

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)
Comment

python list extend

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

extend list 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']
Comment

python list extend

# 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']
Comment

Python List extend()

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)
Comment

PREVIOUS NEXT
Code Example
Python :: python variables and data types 
Python :: what does abs do in python 
Python :: get nth character of string python 
Python :: convert 12 hour into 24 hour time 
Python :: try except in list comprehension 
Python :: python loop until condition met 
Python :: how to add new column in django 
Python :: pandas dummy classification data 
Python :: tanh activation function 
Python :: possible substrings of a string python 
Python :: how to change help command on discord python 
Python :: path in python 
Python :: spark mllib tutorial 
Python :: hash table data structure python 
Python :: time conversion in python 
Python :: python typing union 
Python :: dynamic array logic in python use 
Python :: python Parse string into integer 
Python :: count function in python 
Python :: how do variables work in python 
Python :: if elif and else in python 
Python :: sorting in python 
Python :: transpose matrix python 
Python :: Reset Index & Retain Old Index as Column in pandas 
Python :: Patch loop runner _run_once 
Python :: reverse sublist of linklist 
Python :: pdf reading shows gibberish python 
Python :: how to add the number to email address in faker library in python? 
Python :: Command "python setup.py egg_info" failed setuptools/ gunicorn 
Python :: python generic class inheritance 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =