Skip to content
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
Title: 'isinstance()'
Description: 'Returns True if the given object is the specified type. Otherwise the function will return False.'
Subjects:
- 'Data Science'
- 'Computer Science'
Tags:
- 'Booleans'
- 'Data Types'
- 'Development'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
---

The **`isinstance()`** function determines whether a given object is of a designated value type. If it is, the function will return `True`, otherwise the function will return `False`.

## Syntax

```pseudo
isinstance(object, class)
```

- `object` is the object, or a reference to the object, to be tested.
- `class` is the type the function will use in this assertion (e.g. list, set, etc.).

## Example

```py
var1 = "Hello World!"
var2 = 123

def check_if_string(value):
if isinstance(value, str):
print(f'{value} is a string type.')
else:
print(f'{value} is not a string.')

check_if_string(var1)
check_if_string(var2)
```

This example results in the following output:

```shell
Hello World! is a string type.
123 is not a string.
```