-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions_isinstance().py
More file actions
40 lines (25 loc) · 960 Bytes
/
Functions_isinstance().py
File metadata and controls
40 lines (25 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Python isinstance() Function
# Example
# Check if the number 5 is an integer:
x = isinstance(5, int)
# Definition and Usage
# The isinstance() function returns True if the specified object is of the specified type, otherwise False.
# If the type parameter is a tuple, this function will return True if the object is one of the types in the tuple.
# Syntax
# isinstance(object, type)
# Parameter Values
# Parameter Description
# object Required. An object.
# type A type or a class, or a tuple of types and/or classes
# More Examples
# Example
# Check if "Hello" is one of the types described in the type parameter:
x = isinstance("Hello", (float, int, str, list, dict, tuple))
# Example
# Check if y is an instance of myObj:
class myObj:
name = "John"
y = myObj()
x = isinstance(y, myObj)
# Related Pages
# The issubclass() function, to check if an object is a subclass of another object.