When it is required to get the tuple element of data types, the 'map' method and the 'type' method can be used.
The map function applies a given function/operation to every item in an iterable (such as list, tuple). It returns a list as the result.
The 'type' method returns the type of class of the argument that is passed to it.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
Below is a demonstration of the same −
my_tuple = ('Hi', 23, ['there', 'Will']) print("The tuple is : ") print(my_tuple) my_result = list(map(type, my_tuple)) print("The data types of tuple in order are : ") print(my_result)
The tuple is : ('Hi', 23, ['there', 'Will']) The data types of tuple in order are : [<class 'str'>, <class 'int'>, <class 'list'>]