Those parentheses ()
are for actually calling a certain function instead of merely referring to it.
Consider for example:
def func():
return "I am being called!"
print(func)
# <function func at 0x7f41f59a6b70>
print(func())
# I am being called!
Regarding the: func(x)
versus x.func()
syntax, this is a design / stylistic choice.
The first syntax is associated to procedural design / style, while the second syntax is associated to explicitly object-oriented design / style.
Python (as well as many other general purpose languages) support both.
When func
was designed as:
def func(x):
...
you would use the procedural style.
When func
is designed as:
class MyX(object):
def func(self):
...
you would use the object-oriented style.
Note that this would require x
to be of type MyX
(or a sub-class of it).
More info is available in Python tutorials, e.g. here.
Final note: in some programming languages (notably D
and nim
) there is the concept of Uniform Function Call Syntax, which basically allows you to write function and then have it called with whichever syntax (procedural or object-oriented) you prefer.