3 ms·
After looking at their 3.11 example, I wonder... Why can't we put a function definition in the same line of an if statement? if True: def f(x): return x I
by ufo 4y ago
After looking at their 3.11 example, I wonder... Why can't we put a function definition in the same line of an if statement?
if True: def f(x): return x
Is this just because Python doesn't want to encourage extreme terseness? Or is it also because there would be problems or grammar ambiguities were this to be allowed?
- deleted 4y ago[deleted]
- jwilk 4y agohttps://docs.python.org/3/reference/compound_stmts.html https://docs.python.org/3/reference/compound_stmts.html "Only the [indented] form of a suite can contain nested compound statements; the following is illegal, mostly because it wouldn’t be clear to which if clause a following else clause would belong: if test1: if test2: print(x) "