Python Object-oriented summary

Source: Internet
Author: User

Object-oriented (OOP) concepts

Process-oriented: Early programming concepts, similar to functions, but only executed, without return values, encapsulating functional independent code into functions, and finally sequentially invoking different functions

Functional programming: Not only to execute, but also to return results

Object-oriented: Object-oriented is a larger package that encapsulates multiple methods in an object according to responsibilities, sequentially allowing different objects to invoke different methods

Classes and objects

Classes and objects are the two core concepts of object-oriented programming

A class is a group of things that have the same characteristics or behaviors, which are abstract, cannot be used directly, are called attributes, and behaviors are called methods.

Class is the equivalent of a template that is responsible for creating objects

An object is a concrete existence that is created by a class, can be used directly, and objects created by what class have properties and methods defined in that class.

In program development, there are classes and objects

Define the class first:

classStudent (object):def __init__(self, name, age, Sex): Self.name=name Self.age=Age Self.sex=SexdefStudent_name (self):return 'my name is {}'. Format (self.name)defStudent_sge (self):return 'my age is {}'. Format (self.age)defStudent_sex (self):return 'I am a {}'. Format (Self.sex)

Recreate the object: The Created object has the properties and methods of the class

New_student = Student ('jia'' Boy')print( New_student.student_name ())
New1_student = Student ('jia'boy')
Print (New1_student.student_name ())

Python Object-oriented summary

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.