In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Many novices are not very clear about the concept of object-oriented and class in programming language. in order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
# 1. Object-oriented # process-oriented and object-oriented # process-oriented: process is the process of solving problems, that is, there is a logical order, and programs are written based on this idea. Such as the design flow chart, is a mechanical way of thinking. # advantages: complex process flow, and then simplification # disadvantages: poor scalability # object-oriented: objects are a combination of features and skills, writing programs based on this idea, such as creating a world, the world is made up of objects # advantages: strong scalability # disadvantages: programming complexity is high, prone to overdesign # II, class # objects are a combination of features and skills Class is a combination of similar characteristics and skills of a series of objects. # in the implementation: it must be the first concrete objects, and then the summarized classes. For example, (human, human) # in the program: the class must be defined first, and then the object must be generated. # class format: class class name: # the code inside the class will be executed immediately at the definition stage of the class # for example: class sut: sc='dagschool' def learn (self): print ('is learing') def _ _ init__ (self,name,sex Age): # _ _ init__ automatically triggers self.Name=name self.Sex=sex self.Age=age # self.Name=' Lee'# self.Sex=' male'# self.Age=18 def choose_cou (self): print ('choose') # class view attribute print (sut.__dict__) # _ _ dict__ when calling the class Print (sut.sc) # accesses the namespace of the class "." Access the properties of the previous namespace. Print (sut.learn) # function attribute of learn class # add attribute of class sut.counttry='china'print (sut.counttry) # modify attribute of class sut.sc='DAGSCHOOL'print (sut.sc) # delete attribute del sut.counttryprint (sut.counttry) # function call, must pass parameter sut.learn ('ss') # call class procedure is also called instantiation # 1. The resulting return value is an object, which is an empty object. # 2. Assemble the empty object, together with the class parenthesis parameters when calling the class, into a bunch of parameters, in which the empty object itself is taken as the first parameter, and then passed to the initialized function _ _ init__. For example: sut.__init__ (sut1,' Li', 'male', 18) sut1=sut ('Li', 'male', 18) # sut1 is an object print (sut1.__dict__) print (sut1.Name,sut1.Sex,sut1.Age) # the functions defined in class # are bound to the object, and different objects are different binding methods, and should be called by whoever they are bound to. Whoever calls it will be passed to the object as the first argument. Class sut: sc='dagschool' def learn (self,x,y): print ('% s is learing'% self.Name) print (XMagol y) def _ init__ (self, name, sex, age): # _ init__ automatically triggers self.Name=name self.Sex=sex self.Age=agesut1=sut ('Li', 'male' when calling a class 18) # sut1 is an object print (sut1.__dict__) print (sut1.Name,sut1.Sex,sut1.Age) sut2=sut ('Luo', 'male', 8) sut3=sut ('Hou', 'male', 181) print (sut.learn) print (sut1.learn) print (sut3.learn) print (sut3.learn) sut.learn (sut1,1,2) # same result # functions defined within the class Should have a parameter by default. Example: class Teac: schoo='oldboy' count=0 def _ init__ (self,name,sex,age,level,salary): self.name=name self.sex=sex self.age=age self.level=level self.salary=salary Teacher.count+=1 def teach (self): print ('% s is tacahing'% self.name) t1=Teac ('ii','sdf',19,56,20) t2=Teac (' tr','tf',58,60,1000) t3=Teac ('hg','aop') 68pjm 40100) print (t1.count) # classes and types g = [1pje 2je 3je 4] # g=list ([1pje 2je 3jue 4]) g1=list ([1pe 2m 3jue 4]) g2=list ([1rem 2m 3jue 4]) g1.append (5) # equals to list.append (g1jue 5) # G1 equals to the default parameter selfprint (G1) # understanding of binding method g1.append ('a') g2.append ('b') does it help you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.