Why can't an if be used as statement to another if on the same line?

Viewed 45

An ìf works fine as single line statement, like this:

if True: print('OK')

However, if that is given as statement to another single line if, it generates a syntax error, as for:

if True: if True: print('Breaks with "SyntaxError: invalid syntax"')

Why is this construction a syntax error?

1 Answers

As jarmod pointed, the reference by else clause would not be clear in:

if cond_1: if cond_2: print('if part')
else: print('else part, would that be for cond_1 or cond_2 ?')
Related