Print Type Of Variable In Python
Last Updated : Jul 1, 2023
In this article we will show you the solution of print type of variable in python, Python is a dynamically typed language, and the type of variable is defined at the run time. There are several types of data types including int, float, char, string, list, array, set, etc.
As there are many data types, it can be confusing to recognize them, as a beginner.
Here, to find and print the data type of a variable, we are going to use, the type() and print() functions.
Both of these are built-in functions, which means they are declared when the language was being defined. So, we can call or invoke them directly without declaring them in the first place.
Following is the syntax of the built-in type() function,
Syntax : type(object)
In the type() function, we have to pass a single argument. The built-in type() function returns the class type, of the argument passed, as a value.
The syntax of the built-in print() function is as follows,
In the print() function, we can pass one or many arguments. The built-in print() function, displays the output on the console.
The output to be shown on the console is first converted to a string and then displayed.
Although this doesn't change the type of data type of the arguments passed.
It just converts the output to a string data type so that it can be printed out in the console.
Step By Step Guide On Print Type Of Variable In Python :-
- First, we have declared all four variables, with some data inserted in them.
- Then, we used the built-in type() function, to get the data type of the variable guide_name, along with the built-in print() function, so that the output gets printed in the console.
- In the code output, we can see that the data type of the variable 'guide_name' is <class 'str'>.
- Now, let's check for other variables too! We have used the same built-in type() function, along with the built-in print() function for other variables too.
- So, we can find and print different data types of the different variables using the same method.
Likewise, we can also find the data type of any object in the program in Python, with the help of two simple functions, which are type() and print() functions.
This is how we can print the type of the variable in Python. And now it's time for you to start working on some examples all by yourself!.
I hope this article on print type of variable in python helps you and the steps and method mentioned above are easy to follow and implement.