Python: function and variable with the same name

After you do this:

a = 2

a is no longer a function, it’s just an integer (you reassigned it!). So naturally the interpreter will complain if you try to invoke it as if it were a function, because you’re doing this:

2()
=> TypeError: 'int' object is not callable

Bottom line: you can’t have two things simultaneously with the same name, be it a function, an integer, or any other object in Python. Just use a different name.

Leave a Comment