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 Python type() function to get the type of any variable. You have to use print statement in addition to 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 negative numeric value but you will get the same integer type value.

Get Variable Type of Float Variable

A 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 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 which is a float with 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 about more detail about the Python variables, you may like to read the post based on creating variables in Python.

Reference
How to determine the type of a variable in python

Hope, you like this tutorial of how to check data type in Python. If you have any query regarding the tutorial, please comment below.

Also tell me, which method you are using to determine the type of a variable in Python.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.