python-封装、继承、多态

Python97

封装

面向对象编程有三个特点:封装性、继承性和多态,其中最重要的特征之一就是封装性。封装是指数据和功能的集成。对于封装在对象或类中的属性,我们也可以分两步严格控制对它们的访问:隐藏和开放接口,即以下私有化的属性和方法

[En]

Object-oriented programming has three characteristics: encapsulation, inheritance and polymorphism, one of the most important of which is encapsulation. Encapsulation refers to the integration of data and functions. For attributes encapsulated in objects or classes, we can also strictly control access to them in two steps: * Hidden and open interfaces * , that is, the following * privatized properties and methods *

```python

-- coding: UTF-8 --

@Date :2022/9/6 19:17

class School:
school_name = 'ShanXiPoliceCollege'

def __init__(self, nickname, addr):
    self.addr = addr
    self.nickname = nickname
    self.classes = []

def related(self, class_obj):
    # self.classes.append(class_name)
    self.classes.append(class_obj)
输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长