You are using it wrong. Use it this way:
a = 2 if i in [1, 3, 6] else 7
The general form is:
var = val1 if cond else val2
You are using it wrong. Use it this way:
a = 2 if i in [1, 3, 6] else 7
The general form is:
var = val1 if cond else val2