By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

About lambda.

P: n/a
Some c++ guru said c++ is hard to learn but easy to
use. Is python easy for both aspect? I found lot's of
confused in coding.

#code
from Tkinter import *

def on_click(m):
print m
def lamb_on_click(m):
return lambda : on_click(m)
root = Tk()
btns = ['0', '1', '2', '3']
for n in btns:
b = Button(root, text=n, command=lamb_on_click(n))
#Ok!
b.pack()
root.mainloop()
#

Or,

#code
....
b = Button(root, text=n, command=lambda x=n:
click(x)) #Ok!
....
#

The code above works well too, but follow is NOT! WHY?

#code
....
b = Button(root, text=n, command=lambda :
on_click(n))
....
#

Whichever button be clicked, this only print '3'.

Keyword 'lambda' is just like a macro in c or templete
in c++ or not?


_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
>>>>> "Xin" == Xin Wang <xe*****@yahoo.com> writes:

Xin> Some c++ guru said c++ is hard to learn but easy to use. Is

I would question such a guru. There is nothing "easy to use" about
C++. Or perhaps the Guru hadn't tried any other modern language apart
from C.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.