When it is required to check if a variable is a tuple, the 'type' method can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.
The 'type' method checks to see the type of the iterable/value that is passed to it as an argument.
Below is a demonstration of the same −
my_tuple_1 = (7, 8, 0, 3, 45, 3, 2, 22, 4) print ("The tuple is : " ) print(my_tuple_1) my_result = type(my_tuple_1) is tuple print("Is the given variable a tuple ? ") print(my_result)
The tuple is : (7, 8, 0, 3, 45, 3, 2, 22, 4) Is the given variable a tuple ? True