13. Object-oriented programming of Python advanced functions

Source: Internet
Author: User
Tags class definition

Object-oriented programming of Python advanced features (classes and objects)


First, Class and object:


Process-oriented and object-oriented programming

Process-oriented programming: Functional programming, C-programs, etc.

Object-Oriented Programming: C++,java,python, etc.

Classes and objects: Two important concepts in object-oriented

Class: Is the abstraction of things, such as: Car models

Object: Is an instance of a class, for example: QQ sedan, bus

Example Description:

A car model can abstract the characteristics and behavior of a car, and then it can be used as an instance of a real car entity.




Second, the Python class definition


Definition of Python class:

Use the class keyword to define a class and capitalize the first letter of the class name;

When a programmer needs to create a type that cannot be represented by a simple type, it needs to create a class;

Classes combine important variables and functions, which are also known as "encapsulation";

The structure of the Python class:

>>>class class Name:

... Member variables

... member functions

The creation of the class:

Class MyClass ():

def fun: # There is at least one parameter in the method of the # class self

print "Hello world!"

>>> class Test:

... first = 123

... second = 456

... def f (self):

... return ' test '

...

>>> Milo = Test ()

>>> Loyu = Test ()

>>> Loyu.first

123

>>> LOYU.F ()

' Test '


Object is created:

The process of creating an object is called instantiation;

When an object is created, it contains three aspects of the attribute: the handle, property, and method of the object

Handles are used to distinguish between different objects

The properties and methods of an object correspond to member variables and member functions in a class


This article is from "Meteor Yu" blog, please be sure to keep this source http://8789878.blog.51cto.com/8779878/1832929

13. Object-oriented programming of Python advanced functions

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.