Tuple: Nested Tuple and List 1

Tuple: Nested Tuple and List

# list and tuple can contain mixed datatypes, and nested in anyway

my_list =  [3, "4", [11, "12"], ("a", 2), 5]
my_tuple = (3, "4", [11, "12"], ("a", 2), 5)

print(my_list)
# [3, '4', [11, '12'], ('a', 2), 5]

print(my_tuple)
# (3, '4', [11, '12'], ('a', 2), 5)

Here is what the above code is Doing:
1. my_list is a list containing 5 elements.
2. The first element is an integer 3.
3. The second element is a string “4”.
4. The third element is a list containing 2 elements.
5. The fourth element is a tuple containing 2 elements.
6. The fifth element is an integer 5.

The same is true for my_tuple.

Similar Posts