@classmethod
def func(cls, ...):
do
cls
替代普通类函数中的self
,变为cls
,代表当前操作的是类@staticmethod
def func(...):
do
@property
def func(self):
do
# coding:utf-8
class Test(object):
def __init__(self, a):
self.a = a
def run(self):
print('run')
self.dump()
self.sleep()
@classmethod
def dump(cls):
print('dump')
# cls.run()
# 无法在一个classmethod函数中调用self函数
@staticmethod
def sleep():
# self.dump()
print('i want sleep')
t = Test('a')
t.run()
# Test.dump()
# print('------')
# Test.sleep()
# t.sleep()
# t.dump()
class Test1(object):
def __init__(self, name):
self.__name = name
@property
def name(self):
return self.__name
@name.setter
def name(self, value):
self.__name = value
t1 = Test1(name='dewei')
print(t1.name)
# t1.name = '小慕'
# print(t1.name)
t1.name = '小慕'
print(t1.name)