Menu Close

Python type() Function

In this article, we are going to learn all about the Python type function to find the type of any python object. type function in Python is a very useful function to find the data type of any python object.

In previous python built-in functions tutorials, we have seen lots of Python built-in functions along with examples.

Table of Contents

Python type() function

Python type function is a built-in function in Python that is used to find the type of Python object.

Syntax:

The syntax of type function is:-

type(object, base, dict)

Parameter:

type function in python accepts three parameters:-

  • object:- Required, If one parameter is specified, the type function returns the type of this object.
  • base:- Optional. Specifies the base classes.
  • dict:- Optional, Specify the namespace with the definition of the class.

Return value:

The return value of python type function is type of object.

Example

User type() function to find the type of python object.

print("Type of string:- ", type("programming"))
print("Type of list:- ", type([1, 2, 3, 4, 5, 6, 7, 8]))
print("Type of set:- ", type({1, 2, 3, 4, 5, 6, 7, 8}))
print("Type of tuple:- ", type((1, 2, 3, 4, 5, 6, 7, 8)))

my_dict = {"name": "Vishvajit", "age": 22}
print("type of dictionary: ", type(my_dict))

Output

Type of string:-  <class 'str'>
Type of list:-  <class 'list'>
Type of set:-  <class 'set'>
Type of tuple:-  <class 'tuple'>
type of dictionary:  <class 'dict'>

Conclusion:

So, In this article, we have learned all about Python type function.Type function is very useful when you want to find the type of any python oebject.

If you like this article, please share and keep visiting for further Python tutorials.

Python built-in functions


For more information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts