ParenthesesOnlyIfArgument

Misconception:

When calling a function without arguments, it is not necessary to use parentheses.

Incorrect

() are optional for function calls without arguments

Correct

() are mandatory even for function calls without arguments

Correction
Here is what's right.

Parentheses are required in Python to execute a function call. When calling any function, even a function without arguments, parentheses are required. If no parentheses are added, then the expression evaluates to a function, rather than to the result of calling the function.

def f():
  return 42

print(f)    # the function f
print(f())  # the result of calling function f

Origin
Where could this misconception come from?

Students may have prior knowledge of languages where parentheses are indeed optional for argument-less function calls.

Symptoms
How do you know your students might have this misconception?

A student may write code as follows, assuming that f will be invoked

def f():
  return 42

print(f)

Value
How can you build on this misconception?

At first this misconception may look purely superficial. However, it can be surprisingly deep. In languages where functions are values, it is essential to understand the difference between accessing the function as a value (f), and invoking a function (f()).

In Python we may use parentheses next to any name that refers to a function to invoke that function:

def f():
  return 42

g = f
print(g())  # displays 42

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.