Yes, this video is slightly sarcastic. I would never use it to calculate 1+2. I used an extremely trival problem so that I could better demonstrate the syntax of lambda functions.
@@MrWayneDXYou wouldn't but there are a lot of other instances where it would be easier to define a function and use it all in one line instead of wasting 3 lines of code on it.
They're not hard to understand if they're used for what they're supposed to be used for, simple and short expressions that can be easily expressed in line.
so do you really only use these in specific use cases, or just try and avoid them? Or is it just personal preference? Just out of curiosity of course, I'm in the networking field but I'm teaching myself to code.
I swear someday someone is going to figure out a Python one-liner that attains world peace but no one is going to use it because its "not easy to read"
Note : lambda has many use cases , but key places to use lambda are in amp and filter function please learn about map and filter and how to use lambda in them . Very useful !! 😊
@@NickMak-m2c Both of the above functions, as well as min/max/sorted, take in an iterable (list, tuple...) and a function, and apply that function to each element of the iterable. map returns the result, while filter returns an iterable with the unchanged elements, but only those where the function returned True. As for min, max, and sorted, their optional "key" parameter applies the function to each element and then works with the resulting values instead of the original values. If you don't use lambda, you have to create a new function every time you want to use them. For example, if you want to sort a list of 2-tuples based on the 2nd element, you have to create a function def f(x): return x[1]. That wastes 2 lines, 4 if you comply with PEP8, just so you can write "key=f". If you use lambda, you can create that function in an "anonymous" way, meaning you don't give it a name or anything, it just does something simple. In this case, you could write "key=lambda x: x[1]" and you'd be done. Assigning a name to it is possible, you could write "f = lambda x: x[1]", but it's not recommended in most cases. This makes things so much more readable in functions, and makes them so much more powerful.
WOAHHH thank you!! Just started learning Python recently and lambda definitely was a weird one to learn for me personally, but this all makes sense now 🙏
Lambdas in Python aren't great... you can actually assign them to variables, though: my_lambda = lambda x, y: x + y Then you can call it like any other function: my_lambda(1, 2) Most programming languages support multi-line lambdas and they're essential in functional programming. They're just anonymous functions that you don't need to declare and keep around, and if you have something like Kotlin, they are extremely powerful.
Hey I just started learning python too, do you have any advice about indentation? I get the basics of it but sometimes it gets confusing. Is there a rule or pattern?
@@originaljokester7679 The indentation in Python is absolutely required to delineate code blocks because there are no braces like other languages. Foe xample: if cash > 0: pirin('You do have cash!" else: print('Poor as dirt...." If you don't insert the indentitation (usually four, sometimes two if you want), then Python doesn't know how to process a block.
Your teacher is teaching you that because you will eventually need it. Lambda are essential to keep a clean code and improve readability. Any good programmer knows how and when to use lambdas.
@@philippebaillargeon5204 I know, I understand that now. I was just joking about my attitude back then. I understood how to write functions and recursive functions and even did it well but I was so hung up on thinking that Lambda was a waste of time and an insult to all the effort I put into everything that did the same thing. I'm a little more experienced and greatly more appreciative now
I'm mainly learning game development, so for me, lambda functions have been useful mostly for me in being able to pass a function that requires parameters in places where it's normally not allowed.
I myself never really understood lambda functions, until I watched this video and it clearly explained it in a concise way with a rather simple example. Very good job!
try to code lamda funcrion in other languages and you will understand why its so cool and easy to use. Unfortunatly python does not represent lambda fucntion like in other languges. In python its just boring and useless shit.
I love this content. It is pleasant and simple and helps remember useful stuff. Please keep making more. Lots of programmers ego can be seen in the comment section, which should be ignored.
I use lambda frequently when providing the “key” keyword argument of sorted() or list.sort(). Sure, you could define a function specifically for a special sort, but if you know you will only ever use it on one line of code, you might as well keep that sorting logic all on one line of code.
he is showing things in useless cases to make it easier to explain, you when you are writing code you will need to know how to use the things you learn in a useful way
Also you can conver a function with arguments to an object. (Example): def add(x,y): return x+y print(add(1,2)) # 3 print(lambda:add(1,2)) # object element
Just think of them as the simplest possible kind of function. Assign one to a variable (like any other value) and you have a small reusable function. Why do they exist? In Python, mostly just as "syntax sugar" - a concise way to write tiny functions. They aren't necessary. You could always define a normal function instead. But for tiny functions, it's nicer to have a tiny syntax to go along with them.
@@timber2leaseI’m pretty sure that Anonymous Function = Arrow Function (js) = Lambda (python) But there are probably some scoping differences here and there, idk
i dont code in python much (or at all) but i do make spreadsheets and ive seen the =LAMBDA function but never understood it so this was actually useful
major use case of lambdas: assume you have multiple lines of codes which take similar inputs and applies a function to them in an abstract manner. you can now create a function which takes a lambda as an input and simplify your code. i.e. to build a simple calculator: def main(): x = float(input("first number: ")) y = float(input("second number: ")) operation_type = input("choose one from: add, sub") add_lambda = lambda x,y: x + y sub_lambda = lambda x,y: x - y if operation_type == "add": chosen_operation = add_lambda elif operation_type == "sub": chosen_operation = sub_lambda print(calc(chosen_operation, x, y)) def calc(operation, x, y): return operation(x,y) of course this is a low-level example, but it shows the possibility to remove code redundancy in more complex programs
The core use of a lambda is explained in the video, but I'll just explain a bit further for anyone confused. Functions are good programming practice because they group chunks of similar code (closure) and they allow for reuse by referring to the function's name later in the code. But what if you want the benefits of closure but you don't want to reuse a piece of code? You would then use an anonymous function which has no name and therefore can't be referred to elsewhere in the code. Lambdas are pythons version of anonymous functions.
This does seem a little extra but it’s just the most basic of use cases for these. There are actually many uses to lambda functions, for example sorting by a certain attribute in a class with the .sort() function, or passing a function as an argument into another function. For example, if you had a list of 100 names and you needed to change them in several different ways, you can make a function: def permute(list_names, func): for i in range(length(list_names): func(list_names[i]) Then you could pass a lambda function as an argument into the above function. This use case is also a little silly in terms of effectiveness but it is more like where you’ll actually see them
Oh yessss. I'll steal your idea (for youtube shorts videos never done it before). P.s. I'm kinda joking, the video is great! I liked and subscribed, keep up a great job!
Also, fun math trivia, lambda calculus is something called a functional programming language, which means a programming language dependant mostly on functions Lambda calculus is a special type of that programming language, as it ONLY consists of parameters and functions. It's also the very first functional programming language or even the first programming language and computer to ever exist. It also lead to the Entscheidungsproblem or choice-problem in english which proved that some problems are unsolvable.
An actual use case for this is methods that take a callback as a parameter. Example: instead of _def stop():_ _motor.stop()_ _on_keypress_A(stop)_ you could do _on_keypress_A(lambda: motor.stop())_ which is much cleaner and easier. Edit: fixed italics
In JavaScript (and probably other languages too) this is called an IIFE. In JS, you don't need any fancy keyword. You just need to surround the already-existent function declaration with parentheses, and then call it in the same way you would any other function.
Even a old C64 had that called "Def". You showed a unnamed lambda, so it can not be reused. You can say "A=lambda..." the A is more like a function. Sometimes you need to use function, so you can put it in a lambda.
If you want a named function without writing "return" for a reason, use this syntax: functionName = lambda params: return With functionName being the name of the function, params the parameters (a, b=0, *c, **d) and return is what is returned by the function For example with the function "add" taking 2 numbers as arguments and returning their sum: add = lambda x, y: x+y
You just demystified a concept that I keep having to look up every time I encounter a lambda in someone else's code in a way that the not even GeeksForGeeks could do for me.
names = ['George', 'David', 'Sam', 'Rob'] names.sort(key=str.upper) Sorts by name in a case-insensitive manner. If you only want a partial sort based on the first letter of a given name, instead of the entire name, you can use a lambda that returns the first letter, optionally applying str.upper() to that letter: names.sort(key=lambda s: s[0].upper()) Lambda in Python is intended to be used for that kind of thing - a short, uncomplicated function you only need for one particular use case. You might use it to sort even numbers before odd numbers for whatever reason: nums = list(range(10)) nums.sort(key=lambda n: n%2) The demo was a bad example, intended to illustrate that it's the same as a function, forgetting to illustrate why you might prefer it over a named function in the first place.
Word of advice, if you are making a video about lambda functions, actually explain its use case instead of just writing 1+2 to show that you can do it like that. Lambda functions are really important and useful functions which allows us to pass values to other functions by implementing it in a single line. You won't understand its usecase in web programming but it totally make sense in application programming. I always end up using them in my kivy click event code because kivy doesn't let me pass the values directly or passes a reference that I don't need in my listeners. Thus wrapping the listener call with lambda functions helps to keep code compact and understandable.
I am not coding person , I learnt C , c+ when I WAS in polytechnic college, it was just 6 month of course besides my main course, But now I am in love with this python.
Even this simple example could be appropriate if the evaluation required referencing another variable multiple times. If you wanted to evaluate x^2 + xy + y^2 on a variable with an unwieldy but descriptive name, such as "inputValueX" and "inputValueY" then it would be the following: Typical application: print(inputValueX ** 2 + inputValueX * inputValueY + inputValueY ** 2) With lambda: print( (lambda x,y: x**2 + x*y + y**2)(inputValueX, inputValueY) ) I'm not defending these particular variable names, but I actually find readability improves with lambda, and that's a very simple example compared to what some applications may need.
For someone might wondering, lambda is from lambda calculus. It's a theory of computing and lambda is even older than python lol. And the way you write lambda is a little weird, optimization should be lambda x: lambda y: x + y.
For anyone curious about this type of function, it’s called an anonymous function because it isn’t given a name. It cannot be called by any other code. This exists in other languages as well
People joke about trivial problems like 1+2 or 1+3, but there genuinely is a mathematical problem that is part of the millenium problems known as the "a + b = c" conjecture
Yes, this video is slightly sarcastic. I would never use it to calculate 1+2. I used an extremely trival problem so that I could better demonstrate the syntax of lambda functions.
That made me understand this less. Why would you do that when you can just print(X+Y) or print(1+2)?
@@MrWayneDXI think the video would've been better if it showed how it can be used when mapping over an array or something.
Damage is already done. U can recover you honour now. 😊
@@MrWayneDXYou wouldn't but there are a lot of other instances where it would be easier to define a function and use it all in one line instead of wasting 3 lines of code on it.
Ah, okay. How about a serious one, then?
Can you make a tutorial for 1+3 next?
@Darth Vader and 3+1?
@Darth Vader No need. Already written my code and It says: 31
this is how i calculate 1+3
def add(x, y):
sum=0
for i in range (x):
sum+=1
for i in range (y):
sum+=1
return sum
print(add(1,3))
@@youber3200 that's so cool it worked! There might be a small efficiency problem though, so do you think it could manage 1+4?
@@youber3200 There are too few operations and lines of code, this can't work.
Lambda functions are just like regular functions, except they make your coworkers hate you.
Haha why so? I’m new to programming
@@Millio_4_reallio They're just significantly more difficult to read and understand if you're not used to them.
They're not hard to understand if they're used for what they're supposed to be used for, simple and short expressions that can be easily expressed in line.
I had to follow-up a guy that LOVED them. I swear every other line was a LAM
so do you really only use these in specific use cases, or just try and avoid them? Or is it just personal preference? Just out of curiosity of course, I'm in the networking field but I'm teaching myself to code.
I swear someday someone is going to figure out a Python one-liner that attains world peace but no one is going to use it because its "not easy to read"
Note : lambda has many use cases , but key places to use lambda are in amp and filter function please learn about map and filter and how to use lambda in them . Very useful !! 😊
It’s just easy bro
Max, min, and sorted as well.
@@NickMak-m2c Both of the above functions, as well as min/max/sorted, take in an iterable (list, tuple...) and a function, and apply that function to each element of the iterable. map returns the result, while filter returns an iterable with the unchanged elements, but only those where the function returned True. As for min, max, and sorted, their optional "key" parameter applies the function to each element and then works with the resulting values instead of the original values.
If you don't use lambda, you have to create a new function every time you want to use them. For example, if you want to sort a list of 2-tuples based on the 2nd element, you have to create a function def f(x): return x[1]. That wastes 2 lines, 4 if you comply with PEP8, just so you can write "key=f".
If you use lambda, you can create that function in an "anonymous" way, meaning you don't give it a name or anything, it just does something simple. In this case, you could write "key=lambda x: x[1]" and you'd be done. Assigning a name to it is possible, you could write "f = lambda x: x[1]", but it's not recommended in most cases.
This makes things so much more readable in functions, and makes them so much more powerful.
I agree my friend.
I’ve never come across a situation where lambda map or filters are easier to write or read than comprehension lists
WOAHHH thank you!! Just started learning Python recently and lambda definitely was a weird one to learn for me personally, but this all makes sense now 🙏
Lambdas in Python aren't great... you can actually assign them to variables, though:
my_lambda = lambda x, y: x + y
Then you can call it like any other function:
my_lambda(1, 2)
Most programming languages support multi-line lambdas and they're essential in functional programming. They're just anonymous functions that you don't need to declare and keep around, and if you have something like Kotlin, they are extremely powerful.
Hey I just started learning python too, do you have any advice about indentation?
I get the basics of it but sometimes it gets confusing. Is there a rule or pattern?
@@originaljokester7679 The indentation in Python is absolutely required to delineate code blocks because there are no braces like other languages.
Foe xample:
if cash > 0:
pirin('You do have cash!"
else:
print('Poor as dirt...."
If you don't insert the indentitation (usually four, sometimes two if you want), then Python doesn't know how to process a block.
Dude, this is the best use case of short form content…. learning!? Brilliant 👏👏
My professors teaching me Lambda as if I'm not going to just use regular functions anyway
Your teacher is teaching you that because you will eventually need it. Lambda are essential to keep a clean code and improve readability. Any good programmer knows how and when to use lambdas.
@@philippebaillargeon5204 I know, I understand that now. I was just joking about my attitude back then. I understood how to write functions and recursive functions and even did it well but I was so hung up on thinking that Lambda was a waste of time and an insult to all the effort I put into everything that did the same thing. I'm a little more experienced and greatly more appreciative now
I'm mainly learning game development, so for me, lambda functions have been useful mostly for me in being able to pass a function that requires parameters in places where it's normally not allowed.
It’s really useful for doing function calls in places where you normally would not be able to pass arguments
There is no way that you make me understand a concept that took me like 2 hours to parcially understand in just 30 seconds... thanks dude
Damn, I thought it would write the whole Half-Life code for me.
I myself never really understood lambda functions, until I watched this video and it clearly explained it in a concise way with a rather simple example. Very good job!
try to code lamda funcrion in other languages and you will understand why its so cool and easy to use. Unfortunatly python does not represent lambda fucntion like in other languges. In python its just boring and useless shit.
More python shorts please! This is so helpful
You my friend just summed up the whole python philosophy!
Using lambdas along with map to perform fast operations on lists is what got me into them
I love this content. It is pleasant and simple and helps remember useful stuff. Please keep making more. Lots of programmers ego can be seen in the comment section, which should be ignored.
Excellent explanation,very simple to understand 👍🏻👍🏻♥️
This was a much more succinct explanation than I've heard elsewhere. Thank you.
wow! one of the few programming shorts that is actually useful and very well explained. Good job!
Please make shorts on other python topics..Loved this one.
The best and easiest way i ever saw someone explain lambda. ❤. Thanks mate
Can’t wait for the useful case video, thanks mate !
I use lambda frequently when providing the “key” keyword argument of sorted() or list.sort(). Sure, you could define a function specifically for a special sort, but if you know you will only ever use it on one line of code, you might as well keep that sorting logic all on one line of code.
he is showing things in useless cases to make it easier to explain, you when you are writing code you will need to know how to use the things you learn in a useful way
@@GuizinPE81 yeah mate, reason why I wrote that comment 💪🏽💪🏽💪🏽
@@JordanMetroidManiac in a dict for example ? Can you be more specific ? (I’m a noob over here hahaha)
I wasn’t used to lambda functions until I learn JavaScript. And honestly… they make everything so much easier and quicker.
As a physics students, incase anyone is curious Lambda is also in physics the distance between 2 complete pulses in a wave
Wavelength!
Also you can conver a function with arguments to an object. (Example):
def add(x,y):
return x+y
print(add(1,2))
# 3
print(lambda:add(1,2))
# object element
Thanks for posting. I know many others who start out with Python and struggle with understanding lambda functions.
Keep making these videos. This was really helpful and simple to understand.
Whenever I think of lambda function in Python, I think of anonymous function. So lovely to use, yet takes a good amount of practice to master.
I cannot begin to say how well done and concise this explanation is…you, sir have won the month of January! 🎉
This was so helpful. I have never understood Lambda
you still dont if you think this is how to use these
Just think of them as the simplest possible kind of function. Assign one to a variable (like any other value) and you have a small reusable function.
Why do they exist? In Python, mostly just as "syntax sugar" - a concise way to write tiny functions.
They aren't necessary. You could always define a normal function instead. But for tiny functions, it's nicer to have a tiny syntax to go along with them.
Incredible. I'm all ears for 1-2!
Annonymous functions are popular in JavaScript, where they enjoy being wrapped around eachother in an endless web of confusion.
in js, anonymous functions is something different
@@timber2leaseI’m pretty sure that Anonymous Function = Arrow Function (js) = Lambda (python)
But there are probably some scoping differences here and there, idk
i dont code in python much (or at all) but i do make spreadsheets and ive seen the =LAMBDA function but never understood it so this was actually useful
Great explanation. Thanks!!
major use case of lambdas:
assume you have multiple lines of codes which take similar inputs and applies a function to them in an abstract manner. you can now create a function which takes a lambda as an input and simplify your code. i.e. to build a simple calculator:
def main():
x = float(input("first number: "))
y = float(input("second number: "))
operation_type = input("choose one from: add, sub")
add_lambda = lambda x,y: x + y
sub_lambda = lambda x,y: x - y
if operation_type == "add":
chosen_operation = add_lambda
elif operation_type == "sub":
chosen_operation = sub_lambda
print(calc(chosen_operation, x, y))
def calc(operation, x, y):
return operation(x,y)
of course this is a low-level example, but it shows the possibility to remove code redundancy in more complex programs
Started needing lambdas when I needed to add a function as an argument.
actually really helpful, been confused on stuff like lambda and using classes for a while, was able to easily understand. :D
Instructions unclear, caused a Recursion Cascade and now I have to save the facility
If I see a junior developer do this just know I'm breaking your keyboard
Why
@@dangdrjay3011because they don’t understand what the value of anonymous functions is and they have anger issues…
For those wondering: this is useful for functional programming where you might wanna use functions as input for other functions.
The core use of a lambda is explained in the video, but I'll just explain a bit further for anyone confused.
Functions are good programming practice because they group chunks of similar code (closure) and they allow for reuse by referring to the function's name later in the code.
But what if you want the benefits of closure but you don't want to reuse a piece of code? You would then use an anonymous function which has no name and therefore can't be referred to elsewhere in the code. Lambdas are pythons version of anonymous functions.
wow it makes sense ayo
So if I want to pass new inputs I have to define a new lambda line?
@@AJ.911 if you're going to be reusing it, then you probably want a named function and not an anonymous function.
Lambda is what they're called in Haskell and Java too.
This does seem a little extra but it’s just the most basic of use cases for these. There are actually many uses to lambda functions, for example sorting by a certain attribute in a class with the .sort() function, or passing a function as an argument into another function.
For example, if you had a list of 100 names and you needed to change them in several different ways, you can make a function:
def permute(list_names, func):
for i in range(length(list_names):
func(list_names[i])
Then you could pass a lambda function as an argument into the above function. This use case is also a little silly in terms of effectiveness but it is more like where you’ll actually see them
'lambda'
half life 2 flashbacks
Love your videos bro
You're my hero 😮.. Finally I got it 🎉🎉🎉
Oh yessss. I'll steal your idea (for youtube shorts videos never done it before).
P.s. I'm kinda joking, the video is great! I liked and subscribed, keep up a great job!
for their practical use, they are good for callbacks.
I love python because you just write lambda instead of having some weird specific notation for it
We were taught this today. The tutor can’t teach for sheeet! I just watched a short video and understood it better.
Lambda helps a lot when working with group by operations in dplyr.
Also, fun math trivia, lambda calculus is something called a functional programming language, which means a programming language dependant mostly on functions
Lambda calculus is a special type of that programming language, as it ONLY consists of parameters and functions. It's also the very first functional programming language or even the first programming language and computer to ever exist.
It also lead to the Entscheidungsproblem or choice-problem in english which proved that some problems are unsolvable.
When I made buttons with Tkinter I found out that I need lambda to use a command with parameters
An actual use case for this is methods that take a callback as a parameter. Example:
instead of
_def stop():_
_motor.stop()_
_on_keypress_A(stop)_
you could do
_on_keypress_A(lambda: motor.stop())_
which is much cleaner and easier.
Edit: fixed italics
The first time I found a lambda function in Python, I was amazed. 🐍 is ❤️
wow now I understand how useful it is...
In JavaScript (and probably other languages too) this is called an IIFE. In JS, you don't need any fancy keyword. You just need to surround the already-existent function declaration with parentheses, and then call it in the same way you would any other function.
Made it look so easy
Cool, something new I learned today. I heavily rely on this channel
Even a old C64 had that called "Def". You showed a unnamed lambda, so it can not be reused. You can say "A=lambda..." the A is more like a function. Sometimes you need to use function, so you can put it in a lambda.
That s what I needed to know, thx.
If you want a named function without writing "return" for a reason, use this syntax:
functionName = lambda params: return
With functionName being the name of the function, params the parameters (a, b=0, *c, **d) and return is what is returned by the function
For example with the function "add" taking 2 numbers as arguments and returning their sum:
add = lambda x, y: x+y
You just demystified a concept that I keep having to look up every time I encounter a lambda in someone else's code in a way that the not even GeeksForGeeks could do for me.
Just think of it as an anonymous, unnamed one line function.
@@vorpal22 Well, I don't tend to use those in my code yet, so that explanation still wouldn't have helped me in the past.
Lamdas are the best dude... In every language.... It makes outlr job easier
An idiot admiries complexity, a genius admires simplicity.
~ Terry Davis
as someone quite new to programming it just looks like you made a simple 1+2 into an overly complicated quantum physics problem
as someone not new to programming, yes he did
names = ['George', 'David', 'Sam', 'Rob']
names.sort(key=str.upper)
Sorts by name in a case-insensitive manner.
If you only want a partial sort based on the first letter of a given name, instead of the entire name, you can use a lambda that returns the first letter, optionally applying str.upper() to that letter:
names.sort(key=lambda s: s[0].upper())
Lambda in Python is intended to be used for that kind of thing - a short, uncomplicated function you only need for one particular use case.
You might use it to sort even numbers before odd numbers for whatever reason:
nums = list(range(10))
nums.sort(key=lambda n: n%2)
The demo was a bad example, intended to illustrate that it's the same as a function, forgetting to illustrate why you might prefer it over a named function in the first place.
great explanation
Word of advice, if you are making a video about lambda functions, actually explain its use case instead of just writing 1+2 to show that you can do it like that.
Lambda functions are really important and useful functions which allows us to pass values to other functions by implementing it in a single line. You won't understand its usecase in web programming but it totally make sense in application programming. I always end up using them in my kivy click event code because kivy doesn't let me pass the values directly or passes a reference that I don't need in my listeners. Thus wrapping the listener call with lambda functions helps to keep code compact and understandable.
They are like arrow functions in js, mostly passed as callbacks
It's very often used in tkinter to pass arguments on command functions
Solid prank to pull on my professor before my next homework is due 😂🤦🏼♂️😭
I take the first one, the easiest. 🤣
Thanks!
Liked and subbed.
Cool little explanation!
I am not coding person , I learnt C , c+ when I WAS in polytechnic college, it was just 6 month of course besides my main course, But now I am in love with this python.
This music bops
it would've been good to show a real use case here
I used lambda very much when using TK library.
always heard of lambda but never got to use it or actually see it, seems like arrow functions in JS, cool
Lamba functions are like ternary if else statements. If it's a simple function, just reduce it to a single line
The only ever usecase for those i saw in the map-reduce algorithm
nice, simple, beautiful
Amazing video ❤
Python discovers anonymous self invoking functions
This is interesting, I'll try to figure it out on where it can be used.
Its been months and i have never understood LAMBDA.. But this short vid.. Made it. Possible
Great. Nice music too
It's frequently used in ML for one time data manipulation
Him : it's not funny with one line
Also him : IT TAKES 3 LINES OF CODE
In this case, you could use the operators module.
Even this simple example could be appropriate if the evaluation required referencing another variable multiple times. If you wanted to evaluate x^2 + xy + y^2 on a variable with an unwieldy but descriptive name, such as "inputValueX" and "inputValueY" then it would be the following:
Typical application:
print(inputValueX ** 2 + inputValueX * inputValueY + inputValueY ** 2)
With lambda:
print( (lambda x,y: x**2 + x*y + y**2)(inputValueX, inputValueY) )
I'm not defending these particular variable names, but I actually find readability improves with lambda, and that's a very simple example compared to what some applications may need.
Thank you for your videos 😊
That's soo exhilarating
For someone might wondering, lambda is from lambda calculus. It's a theory of computing and lambda is even older than python lol. And the way you write lambda is a little weird, optimization should be lambda x: lambda y: x + y.
In python I find I use lambda the most when I need to pass parameters to button commands in things like tkinter userforms.
For anyone curious about this type of function, it’s called an anonymous function because it isn’t given a name. It cannot be called by any other code. This exists in other languages as well
By any chance, have you made a tutorial for using python to solve complex mathematical problems ?
People joke about trivial problems like 1+2 or 1+3, but there genuinely is a mathematical problem that is part of the millenium problems known as the
"a + b = c" conjecture
It's just a logical consequence of the definitions of 1, 2, and 3 that make these statements true.
bro really using lambda to slove 1+2 💀
Basicamente uma função anônima. Em JavaScript seria algo como (x,y)=>{return x+y }(1,2)
Nice also
What is this font? Looks gorgeous
Man , the audio is really good, but pls low down the volume, it is in the verge of getting distracting us from the video...