How to Check Variable Type in Python With Examples

Last Updated on June 17, 2021 by Roshan Parihar

In this tutorial, learn how to check variable type in Python. The short answer is: use the type() function of Python to find the type of any variable using Python.

There are many types of variables in Python like Numbers, List, String, Tuple, and Dictionary. These variables are created in different ways. If you take check any variable elements, you may find it difficult to get the type in the first look.

However, Python comes with a simple type() function to make it easier for developers. You can easily get the type of any variable using the simple method given here using type(). You may also like to read how to create variables in Python for all data types.

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

Check Variable Type of Numbers, List, String, Tuple, and Dictionary in Python

If you want to find the type of a variable in Python. You have to use the type() function of Python and pass the variable as an argument. Pass any variable whether it is a number, list, string, tuple, or dictionary. You will get the actual type of variable.

Check the example below to get the type of any variable you want. The given variable is a list variable. However, if you forget about the list variable or other variable types. You can use the method given below to get the type of variable. You may also like to read how to find the data type in Python.

Output

<class ‘list’>

The above example showing that the given variable is a Python list variable. However, you can find many other variables of Python too. The variable can be string, tuple, dictionary, or string.

The type() gives you the type of a variable of any type in the output. You can easily find exactly what is the type of the given variable.

DOWNLOAD Free PYTHON CHEAT SHEET

You may also like to read

I hope you like this post on how to check variable types using Python.

Reference
Stackoverflow Discussion on Getting var Type in Python