Python Automation Development class note "DAY06"-Python Advanced (Class)

Source: Internet
Author: User

Classes and objects

process-oriented programming:
advantages: greatly reduces the complexity of the program
Span style= "font-family:"microsoft yahei"; Font-size:14px "> Cons: a set of pipeline or process is used to solve a problem, the production line of soda can not produce a car, even if it can, is also big change, change a component, reaching
Object-oriented Programming
advantages: It solves the extensibility of the program, A single modification of an object is immediately reflected in the entire system, such as the ability to change features and skills of a character parameter in the game
Cons: Controllability is poor, not like the process-oriented programming pipeline can be very accurate prediction problem processing flow and results, object-oriented program once started by the object

everything in Python is object, and Python3 unifies the concept of classes and types, which are classes. >>> Dict#type dict is Class Dict<class 'Dict'>>>> d = dict (name='Egon')#Instantiate D>>> D.pop ('name')#send a message to D, execute the method of D'Egon'A class is a combination of a feature (the definition of a variable) that is common to a series of objects and a skill (the definition of a function).classChinese:country=' China'    #chinese.__init__ (P1, ' Egon ', ' + ', ' male ')    def __init__(self,name,age,sex):#P1. Name=name;p1. Age=age,p1. Sex=sexSelf. Name=name self. Age=Age self . Sex=SexdefTalk (self):Print('Talking', self) property referencePrint(chinese.country)Print(Chinese.talk) Chinese.talk (123) chinese.x=1Print(chinese.x) chinese.country=123123123123123Print(chinese.country)#instantiation ofclassChinese:country=' China'    #chinese.__init__ (P1, ' Egon ', ' + ', ' male ')    def __init__(self, name, age, Sex):#P1. Name=name;p1. Age=age,p1. Sex=sexSelf. Name =name self. Age=Age self . Sex=SexdefTalk (self):Print('%s is talking'%Self . Name) P1=chinese ('Egon',' -','male')#chinese.__init__ (P1, ' Egon ', ' + ', ' male ')P2=chinese ('Alex','9000','female')#chinese.__init__ (P1, ' Egon ', ' + ', ' male ')Object use: Only one, property referencePrint(P1. Name)Print(P1. Age)Print(P1. SEX)Print(P2. Name)Print(p1.country)Print(P2.country) P1.talk () P2.talk ()classChinese:country=' China'    def __init__(self, name, age, Sex):#self.country=123123123123123123Self. Name =name self. Age=Age self . Sex=SexdefTalk (self):Print('%s is talking'%Self . Name) to view the class namespacePrint(Chinese.__dict__) The spatial P1 of the object=chinese ('Egon',' -','male')#chinese.__init__ (P1, ' Egon ', ' + ', ' male ')P2=chinese ('Alex',' the','male')Print(P1.__dict__)Print(P1. Age)#p1.__dict__[' age ']Print(P1.country,id (p1.country))Print(P2.country,id (p2.country))Print(Chinese.talk)Print(P1.talk) p1.talk ()#Chines.talk (p1)Print(P2.talk) p2.talk ()#Chinese.talk (p2)

Python Automation Development class note "DAY06"-Python Advanced (Class)

Related Article

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.