In Python, you can create a list of tuples containing different types of elements using square brackets and separating the elements with commas.
In this example,
tuple1
and tuple2
.listOfTuples
and initialize it with the tuples.tuple1 = (1, 'a', True)
tuple2 = (2, 'b', False)
listOfTuples = [tuple1, tuple2]
print(listOfTuples)
[(1, 'a', True), (2, 'b', False)]
In this example,
listOfTuples
and initialize it with the tuples.tuple1 = (1, 'a', True)
tuple2 = (2, 'b')
listOfTuples = [tuple1, tuple2]
print(listOfTuples)
[(1, 'a', True), (2, 'b')]
In this tutorial, we learned How to create a List of Tuples in Python language with well detailed examples.