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.
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.
1 2 |
myVarElements = ['Ram', 'Shyam', 10, 'Bilal', 13.2, 'Feroz']; print(type(myVarElements)); |
Output
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
- How to check data type in Python with easy examples
- Resolve the error showing TypeError: ‘list’ object is not callable’ in Python
I hope you like this post on how to check variable types using Python.
Reference
Stackoverflow Discussion on Getting var Type in Python