Class definitions using the Python Basics tutorial _python

Source: Internet
Author: User

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

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.