logo

Python Part6

 
 
 

Python OOP

blue print: 蓝图, 图纸 -> reusable
notion image

为什么需要class

当很多objects具有相同属性和行为时, 我们没必要一个一个object定义; 用同一个class实例化对象可以减少代码.

object的state和behavior

  • state(属性): brand, body type, fuel type, model car, fuel level
  • behavior(函数): 启动, 刹车, 踩油门, 开雨刷, 开大灯, 加fuel

class attribute vs object attribute

本章目录
    1v1免费职业咨询