Object-oriented programming is actually very simple--python object-oriented (elementary article)

Source: Internet
Author: User



In the teaching of Python, many students go to the object-oriented programming this piece began to circle, in order to help everyone better understand object-oriented programming and it can be used in their own development process, features this article.

Overview
    • Process oriented: Write base code from top to bottom according to business logic

    • Function: A function code is encapsulated in a function, it will not need to be repeated later, only the function can be called

    • Object-oriented: classify and encapsulate functions to make development "faster, better and stronger ..."

Process-oriented programming is most easily accepted by beginners, it often uses a long code to achieve the specified function, the most common operation in the development process is to paste the copy, that is: Copy the previously implemented code block to the current function.

WHILE TRUE:    IF CPU utilization  >  90%:         #发送邮件提醒          Connect to mailbox Servers          send mail          Turn off connection      if  hard disk use space  > 90%:          #发送邮件提醒          Connect to a mailbox server           Send mail          close connection      if  memory consumption   > 80%:         #发送邮件提醒           connect to a mailbox server          send mail           Close Connection 

Over time, functional programming has been used to enhance the reusability and readability of code, and it has become:

def send mail (content) #发送邮件提醒 Connect mailbox server send mail close connection while True:if CPU utilization > 90%: Send mail (' CPU alarm ') if hard disk uses space > 90%: Send mail (' HDD alert ') if memory consumption > 80%: Send mail (' Memory alarm ')

Today we're going to learn a new way of programming: Object-oriented Programming (object Oriented Programming,oop, OO programming)
Note: Java and C # support object-oriented programming only, while Python is more flexible in that it supports object-oriented programming and functional programming


Creating Classes and objects

Object-oriented programming is a way of programming, which requires "classes" and "objects" to be implemented, so object-oriented programming is actually the use of "classes" and "objects".

A class is a template that can contain multiple functions and functions in a template.

Objects are instances created from templates that can execute functions in a class through an instance object

650) this.width=650; "src=" http://images0.cnblogs.com/blog2015/425762/201508/271420286872390.jpg "width=" 491 " height= "188" alt= "271420286872390.jpg"/>

Object-oriented programming is actually very simple--python object-oriented (elementary 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.