Would Anonymous Functions Help in Learning Programming/Python?

Cristian super.sgt.pepper at gmail.com
Sat Sep 22 00:07:55 CEST 2007

On Sep 21, 2:48 pm, chris.monsa... at gmail.com wrote:
> There are already anonymous functions in Python.
> lambda x, y, z: x + y + z
> is the same as:
> def _(x, y, z): return x + y + z
> As for the method stuff, check out staticmethod(). If you assign
> staticmethod(<function here>) to an object, it will be treated as a
> normal function and not as a "method."
> I have my own personal opinions about how methods should be in Python,
> but, whatever. It's weird to deal with stuff like this:
> x.y = re.match # Assign a function to an attribute of a class, but it
> doesn't work because you can't assign anything but methods!
> x.y = staticmethod(re.match) # Ugly

True, there is lambda, but that is very limited. It might be useful
for key arguments, but not much else. It doesn't solve the teaching
problem of "See, functions are just like any other data type. You can
assign it to a variable." It would be a footnote if it's mentioned at
all. My hope is to subtly reinforce the notion that functions are data
and can be passed around. The current function declaration doesn't
help with this. Creating a function and assigning it to a name is
exactly what Python does, why not have it come out in the syntax? It's
not necessary, yes, but I think it would be helpful for teaching

Again, it's not necessary as much as it's more intuitive and obvious
what's going on. This helps a beginner sort out the process from the
syntax without taking it on faith. They can see the class declaration
and see "I'm defining just another attribute to this class only this
time it happens to be method".

There is nothing functionally lacking in Python. I'm just curious if
there's anything Python can do syntax-wise to help a person better
grasp programming ideas and Python's inner workings.

More information about the Python-list mailing list