Objects in object (OOP) are a very important point of knowledge that we can simply think of as data and a collection of methods for accessing and manipulating the data. After learning a function, we know that if you reuse code, why use a class instead of a function?
Class has some of the advantages
1, the Class object is polymorphic: that is, multiple forms, which means that we can use the same method of operation for different classes of objects without the need for additional code writing.
2, class encapsulation: After encapsulation, you can directly invoke the class object, to manipulate some of the internal class methods, do not need to let users see the details of the work of the Code.
3, class inheritance: Classes can inherit their methods from other classes or classes, and use them directly.
Defines the syntax of a class (classes)
Copy Code code as follows:
>>> class Iplaypython:
>>> def fname (self, name):
>>> Self.name = Name
Look at the first line, the syntax is followed by the class name, and finally don't forget the "colon", so as to define a class.
Play Snake net Hint: class name, first letter, there is an article of no text, preferably uppercase, so you need to identify each class in the code.
The second line begins with the class method, which, as you can see, is very similar to a function, but unlike a normal function, it has a "self" inside it, and its function is a reference to the object itself.
Source URL: http://www.iplaypython.com/jichu/class.html