A detailed example of a Python class

Source: Internet
Author: User

Programming paradigm

Programming is a programmer with a specific syntax + data structure + algorithm composed of code to tell the computer how to perform the task of the process, a program is a programmer in order to get a task result and a set of instructions, is so-called all roads to Rome, the way to achieve a task there are many different ways, The types of programming that are summed up by the characteristics of these different programming methods are the programming paradigm. Different programming paradigms essentially represent different solutions to various types of tasks, and most languages support only one programming paradigm, and of course some languages can support multiple programming paradigms at the same time. Two of the most important programming paradigms are process-oriented programming and object-oriented programming.

Object-Oriented Programming: OOP Object oriented programing

Use ' Classes ' and ' objects ' to create a variety of models for real-world descriptions.

Several cores facing the opposite:

Class: A class is an abstraction, blueprint, prototype for a class of objects that have the same properties, and a common method of defining the attributes (variables (data)) that these objects have in their classes.

An Object object: an instance of a class that is instantiated after a class, which must be called by the program, and a class can instantiate multiple objects, and each object can have different properties.

Encapsulation Package:

The assignment of data in a class, internal invocation is transparent to external users, which makes the Class A container in which the bread implies the data and methods of the class.

Inheritance inheritance:

A class can derive a subclass, a property defined in the parent class, and the method automatically inherits from the Quilt class.

Polymorphism Polymorphism:

Polymorphism is an important object-oriented feature, an interface, a variety of implementations, refers to a base class derived from a different subclass, and each subclass inherits the same method name, but also the parent class method to do a different implementation!

 1 def dog (NAME,GJ): #定义dog 2 data={3 ' name ': Name, 4 ' GJ ': GJ 5 6         } 7 return Data 8 def pop (NAME,GJ,LEV,HP,MP): #定义人 9 data={10 ' name ': name,11 ' GJ ': gj,12 ' Lev ': hp,13 ' hp ': hp,14 ' MP ': Mp15}16 return data17 def bark (d): Print ("Dog%s: Barking"%d[' na Me ')-def Walk (p): print (' person%s: Speak '%p[' name ') @ Dog1=dog (' rhubarb ', ' + ') print (DOG1) 

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.