I\'m using PyCharm and I have this statement:
a = \'foo\'
b = \'bar\'
a = b + a
and PyCharm highlights the last line saying that:
Just ignore PyCharm, it is being obtuse. The remark clearly doesn't apply when the operands cannot just be swapped.
The hint works for numeric operands because a + b
produces the same result as b + a
, but for strings addition is not commutative and PyCharm should just keep out of it.
If you really want to avoid the message, you could use string formatting:
a = '{}{}'.format(b, a)
but I'd not bother, really.