functions as object | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

functions as object

def multiply(x, y): return x * y a = 4 b = 7 operation = multiply print(operation(a, b)) anyone it is assigned the values to a,b but at the end it shows 28? HOW

29th Jul 2020, 8:06 PM
sayyed usman
sayyed usman - avatar
5 Respuestas
+ 8
Because: 4 * 7 = 28 😐
29th Jul 2020, 8:10 PM
Sadness
Sadness - avatar
+ 4
sayyed usman oh sorry. Actually in the code we assigned a new name to multiply function. Now we have two names multiply and operation which are point to the same object.
29th Jul 2020, 8:28 PM
Sadness
Sadness - avatar
+ 4
See this code: You see that they have the same id becausr thy are point to the same object. https://code.sololearn.com/cTyG18ncyV9c/?ref=app
29th Jul 2020, 8:30 PM
Sadness
Sadness - avatar
+ 2
Just function renamed like made it as alias for multiply.. So then multiply(a, b) is same as operation(a, b): it returning a*b =>7*4=28
29th Jul 2020, 8:09 PM
Jayakrishna 🇮🇳
0
is it doing like this a=x,b=y:?? im asking like this because you wroted like x*y that why @Sadness
29th Jul 2020, 8:16 PM
sayyed usman
sayyed usman - avatar