What is isinstancefunction in Python

What is isinstance() function in Python?

Table of Contents

Python isinstance function is one of the python built-in functions. Python isinstance() takes in two arguments, and it returns true if the first argument is an instance of the class info given as the second argument.

isinstance() Integer check Example

In the example below, we are checking whether 32 is of int type. It returns true as 32 is int.

num = isinstance(32,int)
print(“num is an integer:”, num)
What is isinstance() function in Python?

In the example below, we are checking whether 32 is of str type. It returns false as 32 is int.

num = isinstance(32,str)
print(“num is an integer:”, num)
What is isinstance() function in Python?

isinstance() String check Example.

It is same as the above. In the example below, we are checking the weather the given input is a string or not.

string = isinstance(“Hello”,str)
print(string)
What is isinstance() function in Python?
What is isinstance() function in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training
Enroll Free demo class