Convert string list to tuple Python

  1. HowTo
  2. Python How-To's
  3. Convert List to Tuple in Python

Convert List to Tuple in Python

Python Python List Python Tuple

Created: February-10, 2021 | Updated: February-28, 2021

This tutorial will introduce the method to convert a list to a tuple in Python. Lists and tuples are used to store multiple values in a specific order in Python; the main difference between the list and the tuple is that a list is mutable and a tuple is immutable, which means that a new tuple will be created whenever we need to make any change on a tuple whereas we can make changes on a list without creating a new one. Another difference between a tuple and a list is that the tuple has fewer built-in methods than the list in Python.

Convert a List to a Tuple in Python Using the tuple() Function

The tuple() function is a built-in function in Python that takes an iterable object as input and returns a tuple object as output. We can pass different iterable types like a list, dictionary, or even a string to the tuple() function, and it will return a tuple object.

To convert a list to a tuple, we pass the list to the tuple() function. The code example below demonstrates how to convert a list to a tuple in Python using the tuple() function.

mylist = list((1,2,3,4)) mytuple = tuple(mylist) print(mytuple) print(type(mytuple))

Output:

(1, 2, 3, 4)
Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Python List

  • Append to Front of a List in Python
  • Sort a List of Lists in Python

    Related Article - Python Tuple

  • Get List Shape in Python
  • Convert Tuple to String in Python
    • Append to Front of a List in Python
    • Create Directory in Python
    Convert string list to tuple Python
    report this ad