class Student():
school = 'SH'
def __init__(self, name, age):
self.name = name
self.age = age
def func1(self):
friend = "kk"
print(friend)
return friend
@staticmethod # 静态方法不需要self
def func():
a = 20
print('from func')
return a
@classmethod
def index(cls): #@classmethod无法使用实例对象调用。
print("index(cls)")
# return cls("name1", 25)
return "index"
@property #只能通对象调用,不是用类调用
def fun(self):
print("sss")
return "22"
# @fun.setter
# def fun(self,v): #必须传值
# pass
#
# @fun.deleter
# def fun(self):
# pass
#使用类调用
# ret = Student.school
# print(ret) # 调用类属性的值
# Student.func() # 打印调用 def func(): from func 静态方法
# ret = Student.index() # 类方法 直接调用类方法
# print(ret)
# Student.index() # @classmethod
#对象调用
obj=Student("ALG",20)
# # obj.func1() #实例方法
# # obj.func() #静态方法
# # # obj.index() Error @classmethod无法使用实例对象调用。
print(obj.fun)