TC_DHL
发表于 2021-5-8 00:53:36
class C:
def __init__(self):
self._x = None
@property
def x(self):
pass
# I'm the 'x' property
@x.getter
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
aaa = C()
aaa.x = 5
print(aaa.x)
就很烦...很多就写个例子代码, 不写怎么去使用例子中的代码
跑不脱
发表于 2021-8-10 11:00:00
类,学起来累
EdPan
发表于 2021-8-22 00:18:00
谢谢,学习了
pro2on
发表于 2021-9-7 09:26:45
测试题:
0. issubclass(class,classinfo)
1. isinstance(a,A)
2. getattr(a,'x','no exist')
3. 更改内部程序时,接口可保持不变,用户体验更好
4. x=property(getXsize,setXsize,delXsize)
5.
class CodeA:
@staticmethod
def foo():
print("调用静态方法 foo()")
class CodeB:
@classmethod
def foo(cls): print("调用类方法 foo()")
6. something(func):
def f(self):
self.f = func
def f():
print("I love FishC.com!")
7.
class C: def __init__(self, size=10): self.size = size
@property def XSize(self): return self.size
@XSize.setter def XSize(self, value): self.size = value
@XSize.deleter def XSize(self): del self.size
sunyt
发表于 2021-10-14 14:19:01
这课后题给我看懵了{:7_119:}
大摔蝈
发表于 2022-1-17 18:33:56
{:10_266:}
麻辣小鱼干
发表于 2022-2-21 19:07:20
确实有点复杂,特别是最后一段
class C:
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
这段有另一种写法的翻译吗?
songwentao
发表于 2022-4-3 18:52:32
江南孤雁 发表于 2015-11-17 15:15
类学的很吃力:mad:
me too
爱之承诺
发表于 2022-7-22 22:58:46
{:5_109:}
Vicissitude357
发表于 2022-8-24 15:35:54
懂了
hz00701
发表于 2023-7-31 17:48:49
有点难,得多看看实例
Tkhmily
发表于 2024-7-19 09:51:35
蒙蔽了