W3docs

Convert list to tuple in Python

You can convert a list to a tuple in Python by using the built-in tuple() function.

You can convert a list to a tuple in Python by using the built-in tuple() function. Here's an example:

Convert a list to a tuple using tuple()

python— editable, runs on the server
Info

Watch a video course: Python - The Practical Guide

You can also use a generator expression to convert each inner list to a tuple:

Convert a list of lists using a generator expression

python— editable, runs on the server

Note that tuple() works on any iterable, not just lists. Once a tuple is created, its elements cannot be modified (tuples are immutable).