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
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
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).