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

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • 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.  Python turtle Colors – How to Color and Fill Shapes with turtle Module
  • 2.  Convert String to Integer with int() in Python
  • 3.  Scroll Down Using Selenium in Python
  • 4.  Using Python to Sum Odd Numbers in List
  • 5.  Count Primes Python – How to Count Number of Primes in a List
  • 6.  Ceiling Function Python – Get Ceiling of Number with math.ceil()
  • 7.  Log Base 10 Python – Find Logarithm of Number with Base 10 with log10()
  • 8.  Python sin – Find Sine of Number in Radians Using math.sin()
  • 9.  Using Python to Split String by Tab
  • 10.  Using Python to Get Domain from URL

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