- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 −
Example
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)
Output
The tuple is : ('Hi', 23, ['there', 'Will']) The data types of tuple in order are : [<class 'str'>, <class 'int'>, <class 'list'>]
Explanation
- 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.
- Related Articles
- Why are there separate tuple and list data types in Python?
- Tuple Data Type in Python
- Maximum element in tuple list in Python
- Intersection in Tuple Records Data in Python
- Update each element in tuple list in Python
- How to get Fourth Element of the Tuple in C#?
- How to get Sixth Element of the Tuple in C#?
- How to get Third Element of the Tuple in C#?
- How to get Second Element of the Tuple in C#?
- How to get Seventh Element of the Tuple in C#?
- How to get Fifth Element of the Tuple in C#?
- How to get First Element of the Tuple in C#?
- Standard Data Types in Python
- Python Data Types for Data Science
- Get minimum difference in Tuple pair in Python

Advertisements