While playing golf, I came across a particular problem
>>> print '%'+'-+'[1]+str(5)+'s'%'*' Traceback (most recent call last): File "<pyshell#178>", line 1, in <module> print '%'+'-+'[1]+str(5)+'s'%'*' TypeError: not all arguments converted during string formatting
My assumption was that the operator evaluates from left to right, but in this particular case it seems that even if its string operation, % takes precedence over + and tries to evaluate 's'%'*' before concatenation and crash
This is a well-known documented behavior, or there is something more that is not obvious to me.
source share