diff --git a/content/python/concepts/built-in-functions/terms/isinstance/isinstance.md b/content/python/concepts/built-in-functions/terms/isinstance/isinstance.md new file mode 100644 index 00000000000..3e19c4f5d59 --- /dev/null +++ b/content/python/concepts/built-in-functions/terms/isinstance/isinstance.md @@ -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. +```