What is the Difference between Append and Extend in Python?

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Overview

Append and Extend are two built-in methods that are available in the list data structure of Python. Before starting with append and extend, let's cover some points about list. The list is one of the data structures which is most commonly used in Python along with characteristics. Since a list is mutable so adding, removing, deleting, and updating the elements of lists are easy and very common.

There are many methods that are available in list like:

Append: Append is like adding an element to the existing list.

Extend: Extend is like iterating over an argument and adding each element to the list.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Append in Python

The Append method of the list is used to add an element at the end of the list. It will add an element to an existing list, and the length of the list will be increased by one.

Syntax:

Parameter:

element: It can be any object like a number, a string, or another list that will be considered as a single element and added at the end of the existing list.

Return: It will insert an element at the end of the list which is passed as an argument in the existing list.

Code:

Output:

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

extend() in Python

The Extend method accepts an iterable whose elements will be appended to the list. For example, if the input to extend() is a list, it will concatenate the first list with the other list by iterating over the elements of the input list. This means that the resulting list’s length will be increased with the size of the iterable passed to extend().

Syntax:

Parameter:

Iterable: It can be a list or any iterable which can be appended to the list.

Return: It will insert an iterable object at the end of the list which is passed as an argument in the existing list.

Code:

Output:

Note: A string object is an iterable object, so when we pass the string in the extend() method, it will append each character as if iterating over a string.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Difference Between Append and Extend in Python

AppendExtend
The element passed in the append() argument is added at the end of the list.Iterable is passed as an argument and added at the end of the list.
It will add an element to the list without any changes.Iterable Object will append each of the elements at the end of the list.
The length of the list will increase by 1.The length of the list using extend() will increase by the length of the iterable object.
The time complexity of the append() method is O(1).The time complexity of the extend() method is O(k), where k is the length of the iterable.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Learn more

Conclusion

  • append() is used to add an element at the end of the list.
  • extend() is used to add an iterable object at the end of the list within the list.
  • The time complexity of the append() method is O(1), and the extend() method is O(k), where k is the length of an iterable object.
Hiring Partners:
GGoogleAAmazonMicrosoftFFlipkartAAdobe1200+ more