在互動模式下輸入>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than
Laziness Is a Virtue --- Real programmers are lazy. Not lazy in a bad way, but in the sense that they don’t do unnecessary work. 1.建立函數 def fibs(num): result = [0, 1] for i in range(num-2): result.append(result[-2] + result[-1])
1.格式化 format='hello, %s. Your ID is %d.' values=('thy', 38) print format % values ---> 'hello, thy. Your ID is 38.' 如第二句如示,要修飾多個元素,可以用Tuple,也可以用Dictionary(但不可以用List,因為List會被認為僅僅是一個單值) 2.模板(此功能不是內建的,因此要匯入string庫) import string
0.類的私人性 Python中對象的屬性是可以從外部存取的,本身不直接支援私人性,對此的解釋是 Isn’t it enough that each object manages its own attributes? 在Python中如果要使方法或屬性從外部不可訪問,則必須在名字前加上兩個底線 class Secretive: def __inaccessible(self): print "Bet you can't see me..." def
n大魔力1.建構函式class FooBar: def __init__(self, value=42): self.somevar = value f = FooBar('This is a constructor argument')f.somevar --->'This is a constructor argument'在繼承機制中調用父類的建構函式①調用父類的類建構函式(Unbound)class Bird: def __init__(self)
第六關地址:http://www.pythonchallenge.com/pc/def/channel.html進到頁面後,除了兩張圖片,別無他物,果斷查看網頁原始碼。原始碼中有這麼一句:<!-- <-- zip -->好吧,用zip來替換channel試試看先,http://www.pythonchallenge.com/pc/def/zip.html果然,這張頁面雖然存在,不過是一個提示性的作用,頁面上只有一句話:yes. find the