Determine or Check Data Type in Python With Examples

In this tutorial, learn how to find and check data type in Python with easy examples. The short answer is: use the Python type() function to get the type of any variable. You have to use a print statement in addition to the type function to get the type of any variable.

Check Data Type of Integer Variable

An integer variable is a variable with a numeric value. You can create a positive or negative integer variable. After that, you can find the type of the variable using the type() function.

Use the print statement to print the type in the output. You may also like to read how to create integer in python.

Output

<class ‘int’>

The above example prints the type of the variable in the output section. The output contains the short integer string text as 'int'. You can also use a negative numeric value but you will get the same integer type value.

Bonus: download a Free Python cheat sheet that will show you 20+ most important examples to learn in Python.

Get Variable Type of Float Variable

The float variable contains the numeric value with a decimal point. To find if the assigned value is a float, you have to use the type() function inside which pass the variable as an argument.

Also, use the print statement of Python to print the type of variable in the output.

Output

<class ‘float’>

The above example contains the float assigned value to a variable. The type() is included inside the print statement to print variable type. The output contains the type of variable that is a float with a string 'float'.

Determine Data Type of String Variable

In addition to the above all, you also print the type of the string variable. You have to first assign a string value to any variable. After that, use the type() function inside the print statement.

Output

<class ‘str’>

The output of the above example prints the type of the variable in the given output. The output contains the type of the variable string with 'str'. The 'str' means the variable is of string type of Python.

You may also like to read

If you want to know more detail about the Python variables, you may like to read the post based on creating variables in Python.

DOWNLOAD Free PYTHON CHEAT SHEET

Reference
How to determine the type of a variable in python

I hope you like this tutorial on how to check data type in Python.