Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
It's just a name given for the function parameter (for the code example). You can use anything you want there actually, try replacing 'func' with something, then (unless you missed changing one) I suppose the code will run just fine : )
20th Aug 2019, 6:03 AM
Ipang
+ 1
* Why 'func' in argument? Quoted from the lesson: "Functions can also be used as arguments of other functions." * Why 'func' in return? let's first understand some things: 1. The `add` function has 2 parameters <x> & <y> and return x + y. 2. The `do_twice` function has 3 parameters, <func>, <x> and <y>. Notice `add` is the argument passed for <func> parameter. 5 is the argument for <x> parameter, and 10 is the argument for <y> parameter. `do_twice` function will call `add` function internally, twice, passing value of <x> and <y> as arguments, receive and use the return value from the two calls to `add` function, and pass them (again) to `add` function, and finally return the result. return func(func(x, y), func(x, y)) Is equivalent to ... return add(add(x, y) , add(x, y)) ↓ return add(add(5, 10) , add(5, 10)) ↓ return add( 15 , 15 ) ↓ And finally ... return 30 Hope this helps, you are welcome to confirm should there be any doubt, me or other friends here will try to help : )
20th Aug 2019, 2:10 PM
Ipang