• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Append Multiple Elements to List Using Python

Append Multiple Elements to List Using Python

July 6, 2022 Leave a Comment

To append multiple elements to a list in Python, the easiest way is with the + operator.

a = [1, 2, 3]

b = [4, 5, 6]

c = a + b

print(c)

#Output:
[1, 2, 3, 4, 5, 6]

You can also use the Python extend() function. extend() appends another list in place and returns None.

a = [1, 2, 3]

b = [4, 5, 6]

a.extend(b)

print(a)

#Output:
[1, 2, 3, 4, 5, 6]

When working with collections of data, the ability to easily add items, remove items or change the values in a collection is valuable.

One such case where you want to add items is if you want to add multiple items to a list.

In Python, the easiest way to append multiple elements to a list is with the + operator.

If you have a list and want to add another list to it, then you get a new list which has all of the items from both lists.

Below is an example of how you can append multiple items to a list using + in Python.

a = [1, 2, 3]

b = [4, 5, 6]

c = a + b

print(c)

#Output:
[1, 2, 3, 4, 5, 6]

Using extend() to Append Multiple Items to List in Python

You can also use the extend() function to append multiple items to a list in your Python programs.

extend() appends another list in place and returns None.

Below is a simple example of how to use extend() to append elements to a list in Python.

a = [1, 2, 3]

b = [4, 5, 6]

a.extend(b)

print(a)

#Output:
[1, 2, 3, 4, 5, 6]

Hopefully this article has been useful for you to learn how to append multiple items to a list using Python.

Other Articles You'll Also Like:

  • 1.  Write Float to File Using Python
  • 2.  How to Add Commas to Numbers in Python
  • 3.  Not Equal Operator != in Python
  • 4.  Remove Specific Word from String in Python
  • 5.  Read Last N Lines of File in Python
  • 6.  Difference Between read(), readline() and readlines() in Python
  • 7.  pandas max – Find Maximum Value of Series or DataFrame
  • 8.  Golden Ratio Constant phi in Python
  • 9.  Remove Decimal from Float in Python
  • 10.  Using Python to Increment Dictionary Value

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy