Syntax error when an expression starts with a function call
Sample input:
f(x) = x**2
print(f(2)+1)
Error message:
Syntax error: None:2:11 --> print(f(2)*+1) print( <--
Expected 'if' or '[' or ',' or ')'
Workarounds
- enclose the expression in parentheses:
print((f(2)+1))
- enclose the call in parentheses:
print((f(2))+1)
- make the call not to be the first term in the expression:
print(1+f(2))
- add a prefactor
1
to the term with the call, i.e.print(1*f(2)+1)
The issue occurs for both arithmetic and boolean expressions. A sample function call in boolean expression:
bf(x) = not x
print(bf(true) and false)
Similar to arithmetic expression with a call with prefactor, the error does not occur:
print(not bf(true) and false)
Edited by Ivan Kondov