+ 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?
3 ответов
+ 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
+ 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.
0
if I write operation = multiply then operation behave like multiply?