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 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.
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 argument. Pass any variable whether it is 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 below-given method to get the type of variable. You may also like to read how to find the data type in Python.
myVarElements = ['Ram', 'Shyam', 10, 'Bilal', 13.2, 'Feroz'];
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.
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.
You may also like to read
- How to check data type in Python with easy examples
- Resolve the error showing TypeError: ‘list’ object is not callable’ in Python
Hope, you like this post of how to check variable type using Python. If you have any query regarding the tutorial, please comment below.
Also tell me, which method you are using to get the type of your Python variable.