01 What is object-oriented, basic object-oriented operations

Source: Internet
Author: User

1.0---Object-oriented concepts
.
Class: A category of things with the same attributes and skills; (humans can be made to contain multiple Object(of people) class)
Object: Concrete class of performance, specific to the individual, a real example; (Gao Xiaobo is a person, is a real individual in human beings)

Why study classes, objects: Code blocks can be formed, which can be used to manipulate each other (inheritance between classes, Object-to-class operations), in favor of code specification and reference
.
2.0--- class format
.
Class Body: Includes two part variable parts (static variable), method (function) part (normal function, construction method)

class Person:           #  Person 类名    name=‘有名字‘             #  静态变量,(也叫静态字段)    animal=‘高级动物‘    faith=‘有信仰‘    def work(self):            #  方法(函数)        print(‘有没有工作‘)    def house(self):        print(self)        print(‘有没有房子‘)

.
3.0--- Object-oriented operations
.
The operation of a class can be viewed in two ways: by manipulating the class with the class name and manipulating the class by object
from the angle of the class name:
.
a.-- dict
Person. dict Manipulate all content in the query class;
b.-- the Almighty. (can be realized and additions and changes)

print(Person.name)   # 查Person.age=25    # 增     在类的函数中也可以操作Person.name=‘高波‘    # 改del Person.animal        # 删操作类中的方法(在工作中基本不用)Person.work(11)

.
From the angle of the object

class Person:    name=‘有名字‘ #  静态变量,或者是静态字段    animal=‘高级动物‘    faith=‘有信仰‘    def __init__(self,name,age,sex,hobby):     #  构造方法(每个类都要有构造方法)        self.name=name        self.age=age        self.sex=sex        self.hobby=hobby      # 给对象封装相应的属性(变量,可控);    def work(self):        print(‘有没有工作‘)    def house(self):        print(self)        print(‘有没有房子‘)

ret=Person(‘高波‘,25,‘boy‘,‘不知道‘)
By default, the person's space address is passed to self, and the other arguments are passed in sequentially
#1, the class name + () produces an instance (object, Object space.)
#2, automatically executes the init method in the class, passing the object space to the self parameter of init ,
#3, encapsulates the corresponding property (variable) for the object. Controllable.

Automatically executes the init method in the class, passing the object space to the self parameter of init ,
The procedure for the person () # class name + (): The process of instantiating (the process of creating an object)
Person () Instantiate object, instance, object

a.-- Static variables in a manipulation object
1.0 dict All content in the query object
20,000 can.

print(ret.name)ret.hith=1.68del ret.hobbyret.name=‘高小波‘ print(ret.__dict__)

b.-- Static variables in the object manipulation class

Print (ret.name) # If there are objects in the object will be queried first, there is no word, up one step in the query class
Print (Ret.faith)
c.-- methods in object manipulation classes (working, through objects)
Ret.work ()
Ret.house ()

01 What is object-oriented, basic object-oriented operations

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.