Python type() Function | Object type checking

Python type() function is used to know the type of argument(object) passed as a parameter. It’s a built-in function, no need to import a special module. It’s a have 2 types of the variant.

Syntax

The type() function has two different forms:

object: The type() returns the type of this object if one parameter is specified.

Parameters

name: Name of the class, which later corresponds to the __name__ attribute of the class.
bases: Tuple of classes from which the current class derives. Later corresponds to the __bases__ attribute.
dict: A dictionary that holds the namespaces for the class. Later corresponds to the __dict__ attribute.

Return

The type() function returns the type of the specified object.

Example of Python type Function

1. type() With a Single Object Parameter

Code 1. Simply Return the type of these objects and print in console.

Output:

Python type Function

Code 2: Check a data type

Output:

2. Use of type(name, bases, dict)

Output:

Do comment if you have any doubts and suggestions on this tutorial.

Note: This example (Project) is developed in PyCharm 2019.3 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Python 3.7
All Python Programs are in Python 3, so it may change its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.