Single-line functions

Randall Hopper aa8vb at yahoo.com
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?


Thanks,

Randall


-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list