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