How to Use isinstance() Function in PythonPython Basics


The isinstance() function returns True if the given object is of the specified type, otherwise it returns False.

Example

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

a = 12
print(isinstance(a,int))
print(isinstance(a,str))
print(isinstance(a,float))

Output:

True
False
False

Syntax

isinstance(object, type)

Parameters

Name Description
object An object.
type A type or a class, or a tuple of types and/or classes.

Return Value

It returns True or False.

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