Functions as Objects | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Functions as Objects

def multiply(x, y): return x * y a = 4 b = 7 operation = multiply print(operation(a, b)) can anyone explain how it code works?

30th Apr 2018, 5:08 AM
Lakshman Patel
Lakshman Patel - avatar
3 Answers
+ 2
multiply is a function that returns the multiplication of it's two arguments. operation is assigned to multiply and does the same thing now as multiply so it returns 7*4=28
30th Apr 2018, 5:13 AM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 1
functions are objects, thus, you can assign them to a variable. So calling operation is EXACTLY the same as multiply, with the same arguments.
30th Apr 2018, 5:12 AM
Amaras A
Amaras A - avatar
0
if I write operation = multiply then operation behave like multiply?
30th Apr 2018, 5:17 AM
Lakshman Patel
Lakshman Patel - avatar