Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Difference between append() and extend() method in 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)
Comment

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

PREVIOUS NEXT
Code Example
Python :: how to get text of a tag in selenium python 
Python :: how to add one to a variable in python 
Python :: values django 
Python :: PHP echo multiple lines example Using Nowdoc 
Python :: python serialize 
Python :: heroku python heroku port issue 
Python :: django test imagefield 
Python :: lose your django secret key 
Python :: python insert item into list 
Python :: create jwt token in django 
Python :: zip lists 
Python :: print to screen 
Python :: how to write manual querry in drf 
Python :: run julia in p;ython 
Python :: how stract avery .jpg string in a website python 
Python :: item[0]: (i + 1) * 2 for i, item in (sort_loc) 
Python :: matplotlib pie edge width 
Python :: inherit functions from other classes 
Python :: Reading Custom Delimited file in python 
Python :: python requests with authorisation token 
Python :: feature importance plot using lasso regression 
Python :: pyspark parquet to dataframe 
Python :: create contract from interface in brownie 
Python :: selenium error 403 python 
Python :: how to slice a set in python 
Python :: unpersist cache pyspark 
Python :: godot get scenes from folder 
Python :: activate python venv in windows 
Python :: how to make a bot send whatever you dm it into a server discord.py 
Python :: one line if statement python 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =