What would be the difference between x.func()
and func(x)
?
Thanks!
Asked
Active
Viewed 76 times
1

The shape
- 359
- 3
- 10
-
1one calls a method on the instance x, and the other calls a function with argument x – flakes May 27 '21 at 23:17
-
I remember having answered this question in detail before :) – Mad Physicist May 27 '21 at 23:56
-
:D:D:D:D:D:D:D:D – The shape May 28 '21 at 19:12
1 Answers
3
@flakes answered your question, but if you want to see what it looks like implementation-wise it is something like this:
def func(x):
print("func(x) calls function func passing x as a parameter.")
class X:
def func(self):
print("x.func() calls the method func on x w/ no parameters.")
x = X()
func(x)
x.func()
Output:
func(x) calls function func passing x as a parameter.
x.func() calls the method func on x w/ no parameters.

rhurwitz
- 2,557
- 2
- 10
- 18