Search code examples
pythonmathsum

8/2(2+2) doesn't work in python but 8/2+(2+2) and 8/2*(2+2) do. Why?


Trying to understand operands in python.

8/2(2+2) gave the following error:

TypeError Traceback (most recent call last)
<ipython-input-12-8949a58e2cfa> in <module>
----> 1 8/2(2 + 2)

TypeError: 'int' object is not callable.

Trying to do this like this then using sum() then as python dictionary then in numpy.


Solution

  • Python doesn't support implicit multiplication. When Python tries to run 2(2+2), it tries to call the numeric literal 2 as a function, passing 2+2 as an argument to it. You need to use * between things you want to multiply.