Python Learning Path: object-oriented supplement

Source: Internet
Author: User

1. What is object-oriented programming?

---previously used functions

---class + objects

2. What is a class and what is an object and what does it matter?

Class:

def function 1 ():

Pass

def function 2 ():

Pass

#obj is an object, an instantiated process

obj = Class ()

obj. function 1 ()

########## object-oriented bad #########

########## function Programming Good ###########

Sometimes, function programming can be realized, more troublesome;

Object-oriented can be very short and fast implementation;

3. When should I apply object-oriented?

---Multiple parameters can be encapsulated into object-oriented if multiple functions need to pass in multiple common parameters

---to create something from a template

---application scenarios

#分别采用面向对象和函数的方法实现 "Connect the server, upload files and execute commands, turn off the connection" class SSH:    def __init__ (self,host,port,pwd,username):        Self.host = host ...    def connection (self):        # Create        a connection Self.conn = and fog floats create a linked object ()    def close (self):        # Close        self.conn.    def upload (self):        self.conn. Upload file with link    def cmd (self):        self.conn. Execute command with link obj = SSH (...) Obj.connection () obj.upload () Obj.cmd () Obj.close () #-----------------functional Programming-------------------DEF upload ():    # Connect Server    # upload file    # Close server def cmd ():    # Connect Server    # Execute command    # Close Server

Python Learning Path: object-oriented supplement

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.