How To Convert Tuple To List And List To Tuple

How To Convert Tuple To List And List To Tuple

List To Tuple

aList = [123, 'xyz', 'zara', 'abc']
print (aList)
print ()
aTuple = tuple(aList) # converting list to tuple
print (aTuple)

Output:

[123, 'xyz', 'zara', 'abc']

(123, 'xyz', 'zara', 'abc')

Tuple to List

aTuple = (123, 'xyz', 'zara', 'abc')
print (aTuple)
print ()
aList = list(aTuple)
print (aList)

Output:

(123, 'xyz', 'zara', 'abc')

[123, 'xyz', 'zara', 'abc']

Difference Between Tuple And List In Python

The main difference between Tuple and List is Tuple is immutable and List is mutable.Immutable means Tuples can be not be changed after it got created and Mutable means List can be changed after it got created



Comments