How to Use type() Function in PythonPython Basics


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

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print(type(1))
print(type('A'))
print(type(1.1))

Output:

<class 'int'>
<class 'str'> 
<class 'float'>

Syntax

type(object) or type(name, bases, dict)

Parameters

Name Description
name The class name which becomes __name__ attribute of new type object.
bases A tuple that itemizes the base class of a new type object.
dict A dictionary which is the namespace with definitions for the class body.

Return Value

If there is one parameter, it returns the object type; if there are three parameters, it returns a new type object.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us