Want to know object oriented programming python book? we have a huge selection of object oriented programming python book information on alibabacloud.com
): Self.name=name Self.score=scoredefLanginfo (self):Print '%s:%s'%(Self.name,self.score)classC (Lang):PassclassPython (Lang):defLanginfo (self):Print "Hello%s!"%(self.name) lang1=c ('C + +','9.0') Lang2=python ('Python','8.5') Lang1.langinfo () Lang2.langinfo ()Operation Result:5. polymorphicThe subclass must be an instance of the parent class, and the parent class is not necessarily an instance of the chi
accessed by the class.With dynamic methods There are also static methods, so what if a static method is defined?To define a static method, there are two requirements:1, need to add an adorner "@staticmethod" on the dynamic method2, remove self, Because static methods belong to the class, and self belongs to the objectTo create a static method:@staticmethoddef foo (): print ' This is a static method 'Person:static (): person.static ()Output result:This is a static methodSummary: the difference b
can hold the objectBy encapsulating existing objects, they can be made into new objectsEach object belongs to a typeType, that is, classObject is an instance of a classAn important feature of the class is "what message can be sent to it"Once a class is defined, you can instantiate multiple objects as neededEach object can only accept a specific requestA request that can be sent to an
Python applications support process-oriented programming and object-oriented programming. In the "process-oriented" language, A program is built by a process or a function that can only
The next thing you learn about object-oriented programming is that the basics are not recorded and only some Python-specific or advanced features are recorded.Http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 0014318645694388f1f10473d7f416e9291616be8367ab50001. Definition of classThe d
, and, of course, using Java in a similar way. Because Python supports higher-order functions, the Get/set method can be decorated with adorners as attributes.classStudent (object):def __init__(self, Name, score): Self.name=name self.__score=score @property#Decorate Get method defscore (self):returnSelf.__score@score. Setter#Decorative Set method, a byproduct of @property decoration defscore (self, sc
here: | | __add__ (self, other_color) | Return a new Color made fromAdding theRed, Green andBlue Components | ofThis Color toColor Other_color ' s components. If theSum is Greater than|255, theColor is Set to 255| | __eq__ (self, other_color) | Return TrueifThis Color ' s components isEqual toColor Other_color ' s components. | | __init__ (self, r, G, b) | A New Color withRed value R, Green value G, andBlue value B. All | Components is integersinch theRange0-255.| |
object oriented into introductionProcess-oriented programmingThe core is the process (pipeline thinking), the process is the steps to solve the problem, the process-oriented design is like a well-designed pipeline, consider when to deal with what things. The main applications are in places where little modification is
This article mainly introduces the detailed description of object-oriented programming in Python (I ), this article describes how to create a class, instantiate a class, class attribute, built-in attribute of a special method, static variable attribute, instance variable attribute, method attribute, static method, and
classes at the same time.
Mixin
Mixin design mode
The function of class is extended mainly by multi-inheritance method
Mixin concept
MRO and Mixin
Mixin mode
Mixin MRO
Mro
We use multiple inheritance syntax to implement Minxin
Use Mixin to implement multiple inheritance with great care
First he must show a single function, not an item
Responsibilities must be single, if multiple functions are written, then mu
ensure that only a single instance exists in the current memory, avoiding memory waste!!!When you create an object, you can no longer use it directly: obj = Foo (), and you should call a special method: obj = Foo.dl ().The essence is actually to define a static method, to determine whether there is already a singleton object, if there is a direct return of the Singleton
process-oriented programming (Baidu or Google): (1) Definition:(2) Compare the advantages and disadvantages of functional and process-oriented programming:Classes in Python:(1) definition (Baidu or Google): (2) Description: The classes in Python consist of properties and m
return value must is a string object.
Read the explanation, where to say is the user-oriented, and where the programmer???? See the bold word No, see the slide line has not??? It's all about acting for everyone!!! If you want to be in your own position, well, it seems like such a thing, it is really obscene and vague expression.Do not say, first small try:#!/usr/bin/
The brief generalization of object-oriented programming is to abstract the problem that will be handled into a collection of data and operations, encapsulating it with a class . Where data and operations are called properties of classes, they are generally invariant.Instantiating a class generates the object that we ca
to father, and then to the son of the relationship. And any class, in the end, can be traced back to the root class object, which looks like a backward tree. For example, the following inheritance tree:For a static language (for example, Java), if you need to pass in a animal type , the incoming object must be a animal type or its subclass , otherwise the run () method cannot be called.For Dynamic language
website Explanation:New in version 2.2.
iterator.__iter__()
Return the iterator object itself . This was required to allow both containers and iterators to being used with Thefor andin statements. This method corresponds to Thetp_iter slot of the type structure for Python objects in the python/c API.
iterator . next (
Return the ne
:#Filename:claaorinsvarclassanimal:population=0def __init__(self,name): Self.name=name Animal.population+ = 1defSayhi (self):Print("My name is"+self.name)defHowmany ():#This function does not pass arguments to self #print (' We have ' + animal.population + ' animals ') #use the above code after the program error "Print (' We have ' + animal.population + ' animals ') #Typeerror:must is str, not int " #Animal.population cannot automatically connect to strings, and in Java it can be automatical
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.