Class-Built-in functions
Services to classes and objects.
9 Built-in functions
Issubclass,isinstance,hasattr,getattr,setattr,delattr,dir,super,vars
Note: GetAttr () and delattr () may throw exceptions (such as Attributeerror) to handle exceptions
This article introduces the Python built-in isinstance function in detail:
Isinstance (object, classinfo)
Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof. if object
A one-time fix instanceof and isinstance,instanceof and isinstance are very similar, and the usage is similarly, first look at these two usages:Obj.instanceof (Class)Which means that this object is not of this type,1. An object is an object of its
Isinstance is an intrinsic function syntax in Python: Isinstance (object, ClassInfo) If the argument object is an instance of ClassInfo, or object is an instance of a subclass of the ClassInfo class, Returns True. If object is not a given type, the
DescribeThe Isinstance () function determines whether an object is a known type, similar to type ().
Isinstance () differs from type ():
Type () does not consider a subclass to be a parent class type, regardless of the inheritance
This article mainly introduces how to use isinstance () to judge the variable type in Python. This article first provides an example of isinstance function to judge the variable type, and explains the differences between isinstance and type, for
English documents:isinstance(object, classinfo)Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect o R Virtual) subclass thereof. If Object is a object of the given type, the function always returns
DescribeThe Isinstance () function determines whether an object is a known type, similar to type ().
Isinstance () differs from type ():
Type () does not consider a subclass to be a parent class type, regardless of the inheritance
type,isinstance determine the data type of a variableImport typesType (x) is types. Inttype # determine if int typeType (x) is types. StringType #是否string类型.........--------------------------------------------------------Super disgusting pattern,
Isinstance (object, ClassInfo)
To determine whether an instance is this class or object
object is a variableClassInfo is a type (tuple,dict,int,float)To determine whether a variable is this type
Copy Code code as follows:
Class
English Document: Isinstance (object, ClassInfo) Return True if the object argument is an instance of the ClassInfo argument, or of a (di Rect, indirect or virtual) subclass thereof. If object is a object of the given type, the function always
isinstance (object, ClassInfo)
Determine if the instance is this class or object
object is a variableClassInfo is a type (tuple,dict,int,float)Determine if the variable is of this typeCopy the Code code as follows:
Class Obja:
Pass
A = Obja
Inheritance and polymorphismIn OOP programming, when we define a class, we can inherit from an existing class, the new class is called a subclass (subclass), and the inherited class is called the base class, the parent class, or the superclass (base
Python object-oriented-Get object information type isinstance getattr setattr hasattr
I. type () function
You can directly write the basic data type.int,strAnd so on:
>>> Class Animal (object ):... Pass...>>> Type (123)>>> Type ('20140901 ')>>> Type
Basic usage of python built-in function isinstance, pythonisinstance Syntax: isinstance (object, type)Purpose: To determine whether an object is of a known type.The first parameter (object) is the object, and the second parameter (type) is the type
Isinstance (1, int) to determine if it is of type intIsinstance (1.0, float) to determine if it is float typeIsinstance (S, str) determine if it is a string typeIsinstance (A, dict) determines whether object A is a dictionaryIsinstance is an
Python isinstance function introduction, pythonisinstance
Isinstance (object, classinfo)
Determine whether the instance is of this class or object
Object is a variable.Classinfo is a type (tuple, dict, int, float)Determines whether the variable is
First, Isinstance ()
In Python, you can use the type () and isinstance () functions to determine the object type, while the isinstance () function is more convenient to use than type.Copy the Code code as follows:
# Coding=utf-8
A = 10
def b
One, Isinstance ()
You can use Type () and isinstance () to determine object types in Python, and isinstance () functions are more convenient to use than type.
Copy Code code as follows:
# Coding=utf-8
A = 10
def b ():
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.