- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get tuple element data types in Python
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'>]
- A tuple that contains list is defined, and displayed on the console.
- The map method is used to apply the 'type' method to all elements of the tuple of list.
- This is converted to a list.
- This is assigned to a value.
- It is displayed on the console.
Kickstart Your Career
Get certified by completing the courseGet Started