Member-only story

Python: Isinstance Function Tutorial

Jesse L
3 min readDec 15, 2021

--

Hi everyone, welcome back. Today, we will go over the isinstance() function in Python and see how it works. The isinstance() function is a built in function and its purpose is to return a true or false value depending on whether or not a given object is of a given data type. Let’s get into it.

isinstance() Function

Let’s see how the isinstance() function works:

result = isinstance(3, int)
print(result)
Output:
True

We called the isinstance() function and passed in a 3 as an integer and a data type of an int. The isinstance() function will verify whether or not the passed in 3 value is of the integer data type. As we can see in the output, it returned true, meaning that our passed in value is an integer.

Now let’s keep our 3 value but change our data type to ‘str’ to check against the string data type and see what happens:

result = isinstance(3, str)
print(result)
Output:
False

The isinstance() function returned a false, verifying that our value of 3 is not of the string data type, which is our expected result.

Example with other types

result1 = isinstance(1.1, float)
result2 = isinstance(False…

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet