Method calls ( Python ) | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Method calls ( Python )

What is the method calls ?

30th Jul 2020, 3:57 PM
Noud Al Mansouri
Noud Al Mansouri - avatar
2 Réponses
+ 3
Method: ———— def my_func(): print("spam") print("spam") print("spam") her call ———- my_func() Result: ———— spam spam spam >>>
30th Jul 2020, 4:02 PM
JaScript
JaScript - avatar
+ 1
It is a way to run the code defined by the function. It calls when you add the paranthesis att the end of the function name, and passes the arguments inside the paranthesis to the function code. Without the paranthesis it acts much like an ordinary object in Python like this: def f(x): return x ** 2 print(f(4)) g = f f.a = "Hello world" print(g.a, g(4)) If you instead create a function inside a class, it becomes a class method, and you have to call it through an object of that class: my_object.f(4).
30th Jul 2020, 4:45 PM
Per Bratthammar
Per Bratthammar - avatar