Lambdas should not be assigned to a variable.(according to pep-8) Instead, they should be defined as functions. The primary reason for this is debugging. Lambdas show as in tracebacks, where functions will display the function's name.
the danger of non-inline lambda is their scope. Here's an example of a function for a y=mx+b function maker: >>>def make_y(b): return lambda x: m*x + b >>>y1 = make_y(0) >>>y1(10) NameError... >>>m = 1 >>>y1(10) 10 >>>m = 10 >>>y1(5) 50 So the global scope variable "m" reaches into make_y and changes the output of the lambda. Fun! Could be clever, even, but super dangerous in a massive codebase.
@@DrDeuteron this is not related to using lambdas or their scope , this is just a bad code , first of all you did not encapsulate your parameter in the scope of your function and the rule is it will look for the parameter at global scope . what you did was that make an y = mx + 0 = mx , and the parameter m neither is inside the function nor passed to function . so if you call the function , if there is a m in the global scope it will use it , and if it was not provided it will give you an error . there is no danger related to lambda function's here. you just simply must understand the scope of a variable in a function and classes , and write your code based on the rules. and keep in mind to encapsulate the data as much as possible . remember methods in a class has access to other functions (methods) variable inside the class . but in functional programing we do not have these access between different function and if we want to share them one way is to declare them as Global , or implement those methods inside a class .
@@DrDeuteron the function add or x is not the case here , according to pep 8 you should not name a lambda function it is a bad practice , although it will work but pep 8 suggest that we use lambda for anonymous functions mostly for hand made call back functions . but regardless of that when we learn lambda we use this bad practice for the purpose of understanding the lambda functionality, but the teacher must say that we better not name them and use it as call backs like sorted( list , key = lambda data : data[0] > 0)
@@Indently can make video explaining how can we create a small python environment in our project so that the client doesn't have to install python in their device pls :) that would be really helpful
lambda parameter (space available to put arguments): expression (e.g.: math formula, hence calculator). I'm beginner, it would confuse beginners when different terminology is used.
When u assign a lambda to a variable, the variable contains the address to the lambda function object which is callable with the lambda's parameter list!
The only thing needed to understand whats lambda is to need k ot its, using for creating func, but if u ront want to create func u just create lambda, and its anonymous func
JavaScript arrow functions are roughly the equivalent of lambda functions in python or blocks in Ruby, but they have more intricate details. Arrow functions allow a developer to accomplish the same result with fewer lines of code and approximately half the typing. But in python it has lots of use cases. they are incredible.