@demonly
2017-10-30T14:52:39.000000Z
字数 754
阅读 731
Python
property(fget, fset, fdel, doc) 接受四个方法,创建一个属性。
class Rectangle:
def __init__(self):
self.width = 0
self.height = 0
def setSize(self, size):
self.width, self.height = size
def getSize(self):
return self.width, self.height
size = property(getSize, setSize)
__iter__ 为可迭代对象指定迭代器。
生成器中的等待点使用 yield 语句指定,迭代器通过 next 方法返回值,通过 send 方法传入值。