All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

Print Type Of Variable In Python

Last Updated : Mar 11, 2024

Print Type Of Variable In Python

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,

Syntax: print(object)

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 :-

guide_name = "Talkers Code"
number = 89
javascript = ["reactjs", "nodejs"]
dictionary = {"Apple": "Fruit", "Ball": "Thing", "Cat": "Animal"}
print("The type of guide_name is: ", type(guide_name))
print("The type of number is: ", type(number))
print("The type of javascript is: ", type(javascript))
print("The type of dictionary is: ", type(dictionary))

#Code Output
The type of guide_name is: <class 'str'>
The type of number is: <class 'int'>
The type of javascript is: <class 'list'>
The type of dictionary is: <class 'dict'>
  1. First, we have declared all four variables, with some data inserted in them.
  2. The four variables are guide_name, number, javascript, and dictionary.
  3. 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.
  4. In the code output, we can see that the data type of the variable 'guide_name' is <class 'str'>.
  5. 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.
  6. In the code output, it is mentioned that the data type of the variable 'number' is <class 'int'>, the data type of the variable 'javascript' is <class 'list'>, and the data type of the variable 'dictionary' is <class 'dict'>.
  7. So, we can find and print different data types of the different variables using the same method.

Conclusion :-

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.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪