9.2 構造方法
python 中也屬于自己的構造函數和析構函數,
其中的__init__ 就是在類建立對象的時候自動調用的,而下面兩個函數就是在疊代的時候自動調用的,這是python實作的文法。
類在繼承時不顯示調用父類的構造方法時,父類構造方法中聲明的元素不會被繼承
>>>
ohhh.haha!
i‘m full thanks!
squawk!
traceback (most recent call last):
file "g:\new knowledge\practice\python\test.py", line 21, in <module>
sb.eat()
file "g:\new knowledge\practice\python\test.py", line 5, in eat
if self.hungry:
attributeerror: songbird instance has no attribute ‘hungry‘
hello ,everybody!
9.7遞歸生成器
old
: [1, 2, 3, 4, 5, 6, 7, 8]
new
: [‘foo‘, ‘bar‘, ‘join‘, ‘tu‘]
:
file "g:/new knowledge/practice/python/yield_test.py", line 24, in <module>
print "old\n:",list(flatten(test_char))
file "g:/new knowledge/practice/python/yield_test.py", line 5, in flatten
for element in flatten(sublist):