• 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 / Add Tuple to List in Python

Add Tuple to List in Python

February 27, 2022 Leave a Comment

In Python, we can easily add a tuple to a list with the list extend() function.

list_of_numbers = [0, 1, 2, 3]
tuple_of_numbers = (4, 5)

list_of_numbers.extend(tuple_of_numbers)

print(list_of_numbers)

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

You can also use the += operator to append the items of a tuple to a list in Python.

list_of_numbers = [0, 1, 2, 3]
tuple_of_numbers = (4, 5)

list_of_numbers += tuple_of_numbers

print(list_of_numbers)

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

When working with collections of data in Python, the ability to add and remove elements from an object easily is very valuable.

We can easily append tuples to lists in our Python programs.

The Python extend() function allows us to append items of any iterable object onto a list.

With extend(), we can add a tuple to a list.

Below is a simple example in Python of how to add the items of a tuple to a list.

list_of_numbers = [0, 1, 2, 3]
tuple_of_numbers = (4, 5)

list_of_numbers.extend(tuple_of_numbers)

print(list_of_numbers)

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

Using += to Append Tuple to List in Python

You can also use the Python += operator to add tuple elements to a list. The += operator is most used when incrementing a variable but can also be used to append elements to lists.

Below is an example of how to use += to add a tuple to a list in Python.

list_of_numbers = [0, 1, 2, 3]
tuple_of_numbers = (4, 5)

list_of_numbers += tuple_of_numbers

print(list_of_numbers)

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

Hopefully this article has been useful for you to understand how to add a tuple to a list in Python.

Other Articles You'll Also Like:

  • 1.  Examples of Recursion in Python
  • 2.  pandas max – Find Maximum Value of Series or DataFrame
  • 3.  Using GroupBy() to Group Pandas DataFrame by Multiple Columns
  • 4.  Python dirname – Get Directory Name of Path using os.path.dirname()
  • 5.  Print Approximately Equal Symbol in Python
  • 6.  Pythagorean Theorem in Python – Calculating Length of Triangle Sides
  • 7.  math.radians() python – How to Convert Degrees to Radians in Python
  • 8.  Get Length of File Using Python
  • 9.  Adjusting Python Turtle Screen Size with screensize() Function
  • 10.  Python math.factorial() function – Calculate Factorial of Number

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