type() FUNCTION IN PYTHON | Python Type Function

type() FUNCTION IN PYTHON

If we have some object now, and we want to get the type of that object, we can simply make use of the type function. This function simply returns the type of the object, which is given as an argument. Let’s have a look at an example, which demonstrates the same thing. We will create different variables, and assign different data to them, like string, integer, floating point number, boolean, etc… Once we have the data, we would also get the type of all the data, with help of the type function.

Python Type Function

Let’s have a look at the program now –

As you can see, in the above program, we have created some variables and assigned different data to the variables, like integer, float number, complex number, a string, and a boolean data. After this, we are printing the type of all the objects, as you can see in the above program. Here is the output

As you can see, the objects belong to their respective classes. If you are not already familiar with the concept of object-oriented programming, do not worry at all for now. We will get into that a bit later. But for now, just understand that the object is of that particular type. For example, the object referred by the number variable is of int type.

So, as and when required, you can make use of the type function, to get the type of the object that we have.