How to Find the Data Type of Data in Python 


               


How to Find the Data Type of Data in Python



Python


In this article, we show how to find the data type of data in Python.

To find the data type of data in Python, you use the type() function.

You place the variable inside of the type() function and Python returns the data type.

This is shown in the code below.



So you can see how the type() function reveals the data type of data in Python.

Data types include string, int, float, list, and tuple.

Using the type() function to find the data type is actually very useful, especially when you are debugging an error.

For example, if you are doing a mathematical operation, you know that you cannot add strings with integers or floats.

So if you are adding a string with a float, for instance, Python will throw an error.

By using the type() function for each variable you are dealing with, you are able to see exactly what data type each variable is. Thus, you can easily see why an error is thrown.

So the type() function is very important for determining data types.


Related Resources

How to Show All Tables of a MySQL Database in Python

How to Count the Number of Rows in a MySQL Table in Python



HTML Comment Box is loading comments...