Check Variable Type in Python

Python doesn’t offer exactly the same types of variables as for example C++.
For this reason, you can’t check whether the particular integer is 16-bit, 32-bit or unsigned.

That’s all done behind the scene. But you can determine, for example, whether the variable is an integer or a string.

If you want to check a type of a variable or object you have to use the type function.

This will return the following result.

<class 'int'>
<class 'float'>

Python returns the names of data types in a form that is not particularly elegant. Let’s create a function that will format the result into a more readable form.

Now, let’s assign some values to variables and objects and print them on a console. We will do it for int, float, str, list, dict, tuple, complex, set, bool.

This will give us the following result.

int
float
str
list
dict
tuple
complex
set
bool