All IT Courses 50% Off
Python Tutorials

What is isinstance() function in Python?

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?
Facebook Comments

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.

Related Articles

Back to top button