0
首先,我在Python中的初學者,所以準備了nooby問題))'Lambda格式'之間的區別究竟是什麼?
在本網站上的話題之一,我發現關於使用拉姆達的建議非常有用的一塊功能。
這裏是我的代碼更正前:
def entree1(self): #function that is supposed to change text in
self.configure(text = "X") the label block from whatever it is to 'X'
fen = Tk()
pole1 = Label(fen, text = '|_|')
pole1.bind("<Button-1>", lambda: entree1(pole1)) #event handler reffering to the function above
這裏是我的代碼更正後:
def entree1(self): #function that is supposed to change text in
self.configure(text = "X") the label block from whatever it is to 'X'
fen = Tk()
pole1 = Label(fen, text = '|_|')
pole1.bind("<Button-1>", lambda x: entree1(pole1)) #event handler reffering to the function above
概括地說,我改變拉姆達:一些FUNC到拉姆達X:一些FUNC。
它的工作,這是偉大的,但我無法弄清楚這兩個變種之間的區別。 您能否告訴我在添加x後究竟發生了什麼變化?
謝謝你的時間!
'pole1'的'global'聲明是多餘的。 – jacg 2014-10-10 17:15:59
啊,好吧,我想我明白了。對我而言,這仍然是一個相當古怪的概念,但我認爲真正的理解將隨着時間的推移而來。非常感謝你! – 2014-10-12 12:36:38