Single-line functions

Randall Hopper aa8vb at
Fri Mar 31 16:49:43 CEST 2000

I'll probably hate myself when you tell me why this doesn't work:

   def f(): if a == b: doit()

This yields:

     File "<stdin>", line 1
       def f(): if a == b: doit()
   SyntaxError: invalid syntax

Why is it invalid?  This works:

     if a == b: doit()

and this works:

   def f(): a = b

Which syntax rule did I break?



Randall Hopper
aa8vb at

More information about the Python-list mailing list