python中descriptor的应用

时间:2023-11-19 10:29:50

python中descriptor的应用

1、classmethod。

  1)classmethod的应用。

  python中descriptor的应用

  2)classmethod原理。

  python中descriptor的应用

2、staticmethod。

  1)staticmethod应用。

  python中descriptor的应用

  2)staticmethod的原理。

  python中descriptor的应用

3、property。

  1)property的使用。

  python中descriptor的应用

  如上,因为有x = property(...),所以在使用x时,x表示成实例变量。若写成x=3,则x为类对象变量。

  2)property的原理。

  python中descriptor的应用

参考:https://docs.python.org/2.7/howto/descriptor.html