Search code examples
pythonfunctionargs

Simple *args function not working in Python


the following is getting a "int object is not callable" error message:

def plus(*args):
    return sum(args)

plus(6, 7, 8)

Any ideas as to why? This is taken straight from a online tutorial session so I am sure others have noticed the same.

Thanks


Solution

  • If you try to print sum you'll see that it prints some value. The syntax is correct (in both Python 3 and 2.7). The error is basically saying: sum cannot be called as function, because you assigned something to it that is not callable.

    Tested your code here and here, and works perfectly