How to convert tuples and lists in Python to each other?
To convert a tuple to a list, you can use the list() function. For example:
my_tuple = (1, 2, 3)
my_list = list(my_tuple)
print(my_list)
Output:
[1, 2, 3]
To convert a list into a tuple, you can use the tuple() function. For example:
my_list = [1, 2, 3]
my_tuple = tuple(my_list)
print(my_tuple)
Output:
(1, 2, 3)