>>> ###################### >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>> 'Enter your last name: ' : l, >>> 'Your mobile phone #: ' : p} >>> return d.get >>> ###################### > > > This is an example of a 'closure' is it not?
Yes, though I try not to use the word "closure" because it's a technical distinction that isn't really that useful for beginners because it focuses on the implementation details. That is, when we say the word "closure", we're emphasizing the fact that it's a combination of code and the data that it needs to resolve the code's free variables. And for this discussion, all I really cared about was that we needed something that knows how to be "called". Anything that distracts from that point is something I'm actively trying to avoid, at least at first. We could try to make the code look clever by doing something like: ################################################ make_ask = lambda f, l, p: (lambda key: {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p}[key]) ################################################ But this would be death to the point I was trying to make. :P _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor