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.

Python returns the names of data types in the form that is not particularly elegant. Let’s create a function that will format the result to 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.