syntactic sugar for def?

Arnaud Delobelle arnodel at
Wed Sep 28 23:37:12 CEST 2011

On 28 September 2011 22:26, Ethan Furman <ethan at> wrote:
> I remember that 'class' is sugar for type(....).
> I don't remember if 'def' is sugar for something besides lambda.
> Any clues for me?  Heck, I'll even be grateful for outright answers!

It's not really sugar.  But I think you mean something like this:

>>> class A: pass
>>> type(A)
<class 'type'>
>>> type is type(A)

So the closest you get for functions will be:

>>> def f(): pass
>>> type(f)
<class 'function'>

Try help(type(f)) to see how to use it to create a function object.
The problem is that you need to provide a code object, and the easiest
way to create a code object is to use a def statement :)



More information about the Python-list mailing list