1、类成员
类变量
2、对象成员
对象变量:
私有成员变量 --
共有成员变量
方法:
对象方法:
公有方法
私有方法 --
类方法:
类方法
静态方法
@property 只读,无法修改和删除
--get()可读
--set()可写
--del()可删
value = property(--get, --set, --del)
无- public
单-protect
双-private
析构函数--del()--
示例:
# -*- coding:utf-8 -*- class Fruit: __totalkind = 0 def __init__(self, name, color, price): self.__name = name self._color = color self.price = price Fruit.__totalkind += 1 def __get(self): return self.__name def __set(self, v): self.__name = v def __del(self): del self.__name name = property(__get, __set, __del) def show(self): print(self.__name) @classmethod def getcolor(cls): print (cls.__totalkind) @staticmethod def staticGetColor(): print(Fruit.__totalkind) fruit = Fruit('苹果') print(fruit.name) fruit.name = '123' print(fruit.name) del fruit