Home > Article > Backend Development > What does isinstance mean in python?
In python, isinstance means "determining type"; isinstance() is a built-in function used to determine whether an object is a known type, similar to type().
isinstance() function to determine whether an object is a known type, similar to type().
The difference between isinstance() and type():
type() does not consider the subclass to be a parent class type and does not consider the inheritance relationship.
isinstance() will consider the subclass to be a parent class type and consider the inheritance relationship.
If you want to determine whether two types are the same, it is recommended to use isinstance().
Syntax
isinstance(object, classinfo)
Parameters
object -- Instance object.
classinfo -- Can be a direct or indirect class name, a primitive type, or a tuple consisting of them.
Return value
If the type of the object is the same as the type of parameter two (classinfo), it returns True, otherwise it returns False.
Example:
>>>a = 2 >>> isinstance (a,int) True >>> isinstance (a,str) False >>> isinstance (a,(str,int,list)) # 是元组中的一个返回 True True
Recommended learning:Python video tutorial
The above is the detailed content of What does isinstance mean in python?. For more information, please follow other related articles on the PHP Chinese website!