Python object-oriented simple comprehension

Source: Internet
Author: User

Object-oriented:

is a programming paradigm

Role: improve software reusability and flexibility, extensibility

All things in the world are objects, the object refers to a specific state, characteristics, behavior of the entity Knowledge Point one: code reusegive me a chestnut . For example, Xiao Yue has a girlfriend 1, for some other reason, this girlfriend 1 left, and soon after, Xiao Yue found a girlfriend 2, then this girlfriend 2 and girlfriend 1 must have some basic commonality, such as walking, is a woman, all have their own name, this time, if Xiao Yue is a rich second generation , he wanted to find a small three, small three also have these basic similarities, so he can quickly new out a small three, just need to add the additional features you want on this basisYes, we're going to write these basic functions in code .Note the following:with object-oriented, you can implement several calls to basic functionsDoubt:Passdoes functional programming seem to enable similar code reuse? But the code you write sometimes need to pass in a parameter, to tell the code who is calling it, or before the girlfriend to call this code, you do not know, think is a very scary thing, so through object-oriented can not need to pass parameters directly call, object-oriented will identify themselves, Who is calling this code ... Knowledge Point two: inheritance and encapsulation of codeXiao Yue is northeast, Xiao Yue's life is very happy, they gave birth to a boby, Xiao Yue month as father, this boby will have some placeslike Xiao Yue Moon, right?because he is the child of Yue Moon, handsome appearance, intelligent brain, goodNote: This time the small boby is encapsulated by object-oriented, inheriting the code attributes of Xiao Yue Moon (for example, northeast dialect) Doubtful:functional programming can be achieved AH, why use a polygon object? Functional programming is in the form of a dictionary to write this parent-child relationship to memory, and then to implement the inheritance of some code properties, so write in memory, which allows anyone can change, of course, in our real life this is not allowed and object-oriented will be this small boby package, can be called normally,  And keep the relationship between the inheritance of the people do not know how to achieve, is not change, so you understand .... Knowledge Point three: polymorphic a person can be for eating, can have different forms for example, you can stand to eat, you can also sit and eat knowledge point four: Definition of class
Class Person  (object):    #声明了一个类    Pass people_one = person ("BDS")

class: It's an abstract, generic thing.Person : Representing all people, a species, some of the basic characteristics of man,For example, name, blood, hair, People_one: This is a vivid reality of human beings, is an object sentence: People_one is a demonstration of an object code instantiated by a class person:
Class Person  (object):    def __init__ (self,name)    #初始化函数        self.name = name     def say_name (self):        Print "My name is%s"  % Self.name  

  

A p_one is an object instantiated by a person that executes an initialization function when an object is instantiated, so for example some basic characteristics, a property can be defined by an initialization function: What features define self? A characteristic of eating, everyone is the same, everyone can eat, so this is common to everyone, there is no need to initialize the difference, butFor example, the name, everyone is different, so this name needs to initialize the function to define name, to distinguish each person.  Methods, properties, functions, functions. If there is a cup, he has a variety of properties, long, wide, high, shape it has a function is used to fill the water, we call this water-loading action is called method function to implement various functions of function call function is the method letter ----how-to



From for notes (Wiz)



Python object-oriented simple comprehension

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.