*goes on tutorial for decorators* You: If you haven't seen my video on closures, you may want to check that out since I won't be spending a lot of time on them *goes on video for closures* You: if you haven't seen my video in first time functions you may want to check that out since I won't be spending to much time explaining that Damnit Corey... Nonetheless I love the videos, keep up the good work man.
Haha, sorry about that. Decorators have a few prerequisites that kind've ended up in a chain of videos. Hope you found them useful. Also, I saw the question you wrote about your calculator app in another comment. I'll do my best to answer that one when I have the chance.
Hehe - I want 4 videos deep to get here also. Classes > decorators > closures > here. These are awesome videos by Corey. Each video explains everything awesome
I find Your Tutorials outstanding in terms of ease of understanding. I am 62 years old and haven't touched a keyboard since dbase 3 and Lotus 1-2-3. You are making my learning experience with Python much easier. Thank you very much. Kelley Wooten
I've been working with Python for so long, but after watching Corey's videos, I realized how many basics I was missing out on! Thank you so much, you're just amazing!
I have been using python for the last two years, but after watching some of your videos, I have decided to watch all the basic tutorials from your videos, again. Thank you ver much for giving us point of view.
I've made a few attempts at understanding decorators but you really broke it down very well and I got that "why did this ever seem so difficult?" moment. I apricate your pace and the practical examples. Thanks. You have another subscriber.
In the decorator closure, I noticed that; log_hi = logger('Hi!) and log_hi(), do not need the function to work. So what is the purpose for the function ?
Nice vid , one mention though, @5:13 in the video, in the for loop of javascript , I think the correct line is : result.push(func(arg_list[i])); this way you use the actual array items instead of generating one yourself with i value. Also this way you can let var i = 0 . Thanks
I saw ur first video when i was not able to find a good tutorial on iterators and generators and now i refer to ur videos when i have to know anything bout the language... truly an amazing teacher
I have read so many articles and was still clueless about this concept. I watched your video only for 10 minutes, something that i thought was so complicated, understood in a jiffy. You are awesome. Thank you so much.
6:30 Corey, you a little bit messed up with your JS my_map function :). It behaves in this particular case as its python counterpart only because an array has values [1,2,3,4,5], try to change items in an array(list) and JS results will do not match with python results. It should look like this: function square(x) { return x * x; } function my_map(func, arg_list) { const result = []; for (var i = 0; i < arg_list.length; i++) { result.push(func(arg_list[i])) } return result; } var squares = my_map(square, [1,2,3,4,5]) console.log(squares) BTW. I've been watching you for a wile and today actually decided to subscribe. A good and useful channel, a good explanation.
Sorry for the super late reply. Yes, that's right. Others have pointed this out as well. I should have caught that when I first ran the code with the 0 index and got the wrong result. Oops! Thanks for the correction!
After reading what the dictionaries say in so many words and very confusing, amazing Corey you did it in a single line very clear. This makes me think "you should be hired by dictionary entities to give definitions". Thanks for your help!
This is by far the best explanation one can find on youtube about the flow of execution, which is so important for anyone to understand really hard one grasp at first in python
I know this is an older video but I just wanted to say how much your videos have helped me to learn Python! I've made my first ever little programme the other day and seeing it actually work and do stuff amazes me. You have made learning Python so much easier than other resources I've looked at. I haven't had the need to use first-class functionality, but your explanations and examples have made it make so much sense! Thank you so much :D
Honestly, you should make a full Functional Programming course. I'm writing this comment and haven't even watched the whole video yet. Thank you so much.
Your explanation is really simple and clear. I started to learn js fundamental and stumbled upon first class function concept. Got confused for couple of hours and after watching your explanation made me understand it clearly. Cheers.
Was trying to learn python syntax for ML and this has really cleared things up! Don't know if you take suggestions but I write notes down for you videos and would love it if you could provide a textual overlay of what topic you're covering. Had to playback a few times to figure out when you switched from passing function example to the return function example.
I know I'm late but I have to say, THANK YOU!! I mean your videos are just perfect, your teaching is amazing, you explain everything so clearly, the quality of the audio and video is also just amazing! Best videos for learning python(and other programming languages) on RUclips.
Thanks, Corey! Great tutorial as always. However, I think it's important to make it clear that the examples you're giving are just intended to illustrate the concepts of first-class/higher-order functions, etc., and that the same results can be achieved in a more simple and/or readable way: Examples 1 & 2: def exp_list(exp, lst): exped = [i ** exp for i in lst] return exped print(exp_list(2, [1, 2, 3, 4, 5])) # outputs [1, 4, 9, 16, 25] print(exp_list(3, [1, 2, 3, 4, 5])) # outputs [1, 8, 27, 64, 125] Example 4: def wrap_text(tag, txt): print(f"{txt}") wrap_text("h1", "This is a headline") # outputs This is a headline wrap_text("p", "This is a paragraph") # outputs This is a paragraph
Excellent video. This is kind of abstract, but with this excellent explanation and simple examples that do not involve other complications but just illustrate the point at hand, everything is clear. I'm really enjoying this and the other Python tutorials from Corey Schafer. Thanks a lot!
Crazy how sometimes when you read a book, or some instructions, the concept just doesn't stick because of the poor examples being used. This explanation made prefect sense and now I think I have grasped closures. This is the first video of yours I have watched. You have a new subscriber!
I like your explanations and the clarity of your voice. Not to disparage other tutorials on here but most of the Hindi speakers are way hard to understand. Thank you for creating your channel!
in 11:00...15:00 we could execute wrap_text subfunction also this way: html_tag('h1')('Test Headline') so in first brackets we have parameters for main function and in second brackets we have parameters for subfunction. Understanding that - it's much easier to understand what happends between 11:00...15:00 Corey, thank you for very good tutorials.
This video helped. I have been trying to understand higher order functions and have seen a video on another channel and that video made me confused even more. This video really helped. Specially the fact that you used a semi real world example when explaining why would we ever want to return a function from a function helped me understand the importance of higher order functions more. Thank you.
The wrap_text function example after 11:00 would look very nice and readable with python3's f-strings. Thanks for all your hard work, Corey! I really love your videos.
+Corey Schafer Thanks very much for all your great tutorial, Corey! FYI, there's one mistake in your my_map() function example, using cube: it should read: cubes = my_map(cube, [1 ,2 ,3 ,4 ,5]), then print(cubes) instead of squares ---> print(squares). And you can but you don't "have to" move the cube function above with the square function. No big deal, just in case it confuses some people.
Hi Corey, thanks for your videos. It certainly helps me clarify concepts and I appreciate what you are contributing to the community. It all works as an explanation, however there are two errors in your JS code that impact the result. Below is version 1.1. I've added it here so other viewers can see a working example of cube and square would get the expected result. I don't think markdown works here, so hopefully other viewers will be able to understand the code in this format. ``` function cube(x){ return x * x * x; } function square(x){ return x * x; } function my_map(func, arg_list){ result = []; //for(var i = 1; i
Another use case is to allow a user to select what type of algorithm they want to use for a solver. A generic solver wrapper can then be used to call the algorithm (function) option the user selects at runtime, without having to class everything. Also useful for profiling different functions which perform the same task.
Great, thank you very much! I've been using this without knowing the term, it's really helpful to see it on a easy to understand language like python, i saw this on class but the examples were done with a functional programming and for someone that has only been in procedural programming, it was really confusing
Hi, I've started to learn with You this year. You do a lot for other people . In this not easy time develop skills, and learning is the one thing which so meaningfull (sorry for my english, I hope its clear :)it gives hope and enjoy:)The way You speak is perfect, also for people who don't speak english very well.
Finally got it. no wonder so many courses drop the ball at closures, decorators, getters setters. Hard part is seeing the inner is accessed by a variable defined as the call of the outer.
Very well explained. Thank you very much. I know a lot of programming languages, but everytime i learn a new one i got the feeling, that the concepts are just "Pointers of C in more complicated". But maybe that's just me :D
As I was reviewing python OOP, I found the Schaferian loop. the "Class & Static method" lesson led to "Decorators" which led to "Closures" and lastly to this "First-class". This will lead back to the first lesson. Till I die.
I felt extremely dumb after watching the video and still not getting the point, but then an idea came up in my head and made this example, where I finally understood. Might help you as well def custom_sum(first_num): def wrap(second_num): print(first_num+second_num) return wrap two_plus_something = custom_sum(2) two_plus_something(5) two_plus_something(10) two_plus_something(20) output: 7 12 22
I feel comfortable to think like that-> the upper function creates a template for the inner function which then works on variable over the template to produce output.
I started with python beginners, tutorial #8 on Functions, then Classes.. in order to learn decorators I needed to learn closures.. I have to go back to beginners tutorial #9 at some point :D Thank you so much for amazing lectures...
Big fan of your tutorials, very well done and very organized. I would like you to point to an error in your javascript code at 6:27. The error you got can be resolved by adding arg_list[i]) not i to the func() as below: function my_map(func, arg_list){ result = []; for(var i = 0; i < arg_list.length; i++){ result.push(func(arg_list[i])); } return result; } The fix you did will only work if the arg_list is starting with 1 and incrementing by 1. Because you will always operate on the index numbers not the item in that index.
Hey Corey, it would be great if you add these two videos (First-Class Functions, Closures ) into a Python playlist (after Function video). It would be perfect continue and flow in that playlist. You have the best Python tuts in youtube (I guess not only in youtube)
Love these videos ... I see at 04:14, you looked to demonstrate that you can pass a function to another function as an argument. But, you already demonstrated that with the print() function. But the map() function reinforced the idea ... btw, you’re presentation of material is perfect - not too slow, not too much. Very very well demonstrated too. Nice teaching style.
this video solved many doubts, from map to first class function to closures and I just realised at 11:00 you can use lambda function instead of wrap_text
Thank you so much Corey, this is really great video. I've only seen this one from you but definitely I am going to check more of your Python videos. If others are also as good as this one, I will support you, you have my word :) . Thanks again.
Another good example of passing a function reference is the compare function as an argument in most (all?) sort functions. The compare done in a sort is data or result-order dependent and has too be supplied by the programmer.
Rabbit hole: Classes > Decorators > Closures > First-Class Functions. Thank you Corey
For me it was Multiprocessing > Threading > Decorators > Closures > First-Class Functions. Great videos!!
this is exactly what happened rip
For me as well
@@tahsintariq8757 me too
yeah wtf lol
*goes on tutorial for decorators*
You: If you haven't seen my video on closures, you may want to check that out since I won't be spending a lot of time on them
*goes on video for closures*
You: if you haven't seen my video in first time functions you may want to check that out since I won't be spending to much time explaining that
Damnit Corey...
Nonetheless I love the videos, keep up the good work man.
Haha, sorry about that. Decorators have a few prerequisites that kind've ended up in a chain of videos. Hope you found them useful. Also, I saw the question you wrote about your calculator app in another comment. I'll do my best to answer that one when I have the chance.
same
Hehe - I want 4 videos deep to get here also. Classes > decorators > closures > here. These are awesome videos by Corey. Each video explains everything awesome
You're Darth Vader, you should know how to code.
Same scenario over here.
I ended up here because I was watching "Python OOP Tutorial 3: classmethods and staticmethods". Thats a chain invocation of tutorials :D:D:D
haha same
lol same
🙃🙃
hahah same
same! xD
Corey is a beast at teaching people how to code.
I find Your Tutorials outstanding in terms of ease of understanding. I am 62 years old and haven't touched a keyboard since dbase 3 and Lotus 1-2-3. You are making my learning experience with Python much easier. Thank you very much. Kelley Wooten
Woooooo Go Kelley!
I've watched half a dozen videos on Python first class functions but only now, after watching this from Corey, do I understand it.
I've been working with Python for so long, but after watching Corey's videos, I realized how many basics I was missing out on! Thank you so much, you're just amazing!
I have been using python for the last two years, but after watching some of your videos, I have decided to watch all the basic tutorials from your videos, again. Thank you ver much for giving us point of view.
Some tutorials never gets old! Such a great teacher
This guy really knows how to explain programming languages. Amazing!
you're a freak of nature, my guy. You just took me to that next Python level. THANK YOU!!
I've made a few attempts at understanding decorators but you really broke it down very well and I got that "why did this ever seem so difficult?" moment. I apricate your pace and the practical examples. Thanks. You have another subscriber.
In the decorator closure, I noticed that; log_hi = logger('Hi!) and log_hi(), do not need the function to work. So what is the purpose for the function ?
Nice vid , one mention though, @5:13 in the video, in the for loop of javascript , I think the correct line is : result.push(func(arg_list[i])); this way you use the actual array items instead of generating one yourself with i value. Also this way you can let var i = 0 . Thanks
finally found someone who got me crystal cleared with first class functions, closures and decorators......
good work Corey !
I saw ur first video when i was not able to find a good tutorial on iterators and generators and now i refer to ur videos when i have to know anything bout the language...
truly an amazing teacher
I have read so many articles and was still clueless about this concept. I watched your video only for 10 minutes, something that i thought was so complicated, understood in a jiffy. You are awesome. Thank you so much.
I have never seen anything explained anywhere just like you did. THANK YOU. You are really the BEST teacher.
Very nice. Well thought out examples for a topic that's rarely covered.
6:30 Corey, you a little bit messed up with your JS my_map function :). It behaves in this particular case as its python counterpart only because an array has values [1,2,3,4,5], try to change items in an array(list) and JS results will do not match with python results.
It should look like this:
function square(x) {
return x * x;
}
function my_map(func, arg_list) {
const result = [];
for (var i = 0; i < arg_list.length; i++) {
result.push(func(arg_list[i]))
}
return result;
}
var squares = my_map(square, [1,2,3,4,5])
console.log(squares)
BTW. I've been watching you for a wile and today actually decided to subscribe. A good and useful channel, a good explanation.
Sorry for the super late reply. Yes, that's right. Others have pointed this out as well. I should have caught that when I first ran the code with the 0 index and got the wrong result. Oops! Thanks for the correction!
I was about to point out the same thing
Or you could use For...of, or For...each functions.
After reading what the dictionaries say in so many words and very confusing, amazing Corey you did it in a single line very clear. This makes me think "you should be hired by dictionary entities to give definitions". Thanks for your help!
This is by far the best explanation one can find on youtube about the flow of execution, which is so important for anyone to understand really hard one grasp at first in python
I know this is an older video but I just wanted to say how much your videos have helped me to learn Python! I've made my first ever little programme the other day and seeing it actually work and do stuff amazes me.
You have made learning Python so much easier than other resources I've looked at. I haven't had the need to use first-class functionality, but your explanations and examples have made it make so much sense!
Thank you so much :D
Honestly, you should make a full Functional Programming course. I'm writing this comment and haven't even watched the whole video yet. Thank you so much.
Your explanation is really simple and clear. I started to learn js fundamental and stumbled upon first class function concept. Got confused for couple of hours and after watching your explanation made me understand it clearly. Cheers.
I love the ways you teach. My words are not enough to explain how much I love your teaching style and high level content.
i was struggling to understand this concept, this is the BEST EXPLAINATION ON THE INTERNET.
Your explanation helps me internalize the topics , I mean they fall at the right place, they are meant to be with ease.
Thanks a lot.
Was trying to learn python syntax for ML and this has really cleared things up! Don't know if you take suggestions but I write notes down for you videos and would love it if you could provide a textual overlay of what topic you're covering. Had to playback a few times to figure out when you switched from passing function example to the return function example.
The series is super helpful for a person like me that has no computer science background.
Been watching a lot of tutorial videos but yours is the best! Simple and straight to the point! Thanks a lot.
I know I'm late but I have to say, THANK YOU!! I mean your videos are just perfect, your teaching is amazing, you explain everything so clearly, the quality of the audio and video is also just amazing! Best videos for learning python(and other programming languages) on RUclips.
Thanks, Corey! Great tutorial as always.
However, I think it's important to make it clear that the examples you're giving are just intended to illustrate the concepts of first-class/higher-order functions, etc., and that the same results can be achieved in a more simple and/or readable way:
Examples 1 & 2:
def exp_list(exp, lst):
exped = [i ** exp for i in lst]
return exped
print(exp_list(2, [1, 2, 3, 4, 5])) # outputs [1, 4, 9, 16, 25]
print(exp_list(3, [1, 2, 3, 4, 5])) # outputs [1, 8, 27, 64, 125]
Example 4:
def wrap_text(tag, txt):
print(f"{txt}")
wrap_text("h1", "This is a headline") # outputs This is a headline
wrap_text("p", "This is a paragraph") # outputs This is a paragraph
Excellent video. This is kind of abstract, but with this excellent explanation and simple examples that do not involve other complications but just illustrate the point at hand, everything is clear. I'm really enjoying this and the other Python tutorials from Corey Schafer. Thanks a lot!
Man! Corey you're really great at explaining things, my mind actually blown... Thank you so much!
classmethods and staticmethods >>> Decorators >>> Closures >>> First-Class Functions.
Keep the GOOD work Sir!
Crazy how sometimes when you read a book, or some instructions, the concept just doesn't stick because of the poor examples being used. This explanation made prefect sense and now I think I have grasped closures. This is the first video of yours I have watched. You have a new subscriber!
almost 2023 and still very helpful, thanks a lot for your tutourials
I like your explanations and the clarity of your voice. Not to disparage other tutorials on here but most of the Hindi speakers are way hard to understand. Thank you for creating your channel!
I especially appreciate your going through the python and javascript together.
Thanks, finally I understood what is first class functions.
in 11:00...15:00
we could execute wrap_text subfunction also this way:
html_tag('h1')('Test Headline')
so in first brackets we have parameters for main function and in second brackets we have parameters for subfunction.
Understanding that - it's much easier to understand what happends between 11:00...15:00
Corey, thank you for very good tutorials.
The more closures you add, to closures, it makes more sense as you're like, saving information to make a function be used for a specific purpose.
This video helped. I have been trying to understand higher order functions and have seen a video on another channel and that video made me confused even more. This video really helped. Specially the fact that you used a semi real world example when explaining why would we ever want to return a function from a function helped me understand the importance of higher order functions more. Thank you.
great example for the utility of returning a function. Really helpful
Awesome explanation video for both languages, I was struggling past one week on this topic watching more videos finally figured out all.
Well explained and to the point, i cant believe this guy is real
Best videos on youtube. The way you explain concepts are simply amazing
You're amazing guy Corey. Thank You very much for Your work.
Thanks!
when I face some difficulty in understanding python concept , I will first search to see if Corey have video about that topic , Thank you very much
Thanks a lot for the explanation! I was so confused with decorators, now it makes so much more sense to me :) You are just amazing!
The wrap_text function example after 11:00 would look very nice and readable with python3's f-strings. Thanks for all your hard work, Corey! I really love your videos.
Fast becoming a fan here, Mr. Schafer. A+ on the didactics and presentation.
+Corey Schafer Thanks very much for all your great tutorial, Corey!
FYI, there's one mistake in your my_map() function example, using cube:
it should read: cubes = my_map(cube, [1 ,2 ,3 ,4 ,5]), then print(cubes)
instead of squares ---> print(squares).
And you can but you don't "have to" move the cube function above with the square function.
No big deal, just in case it confuses some people.
This guy is beast at explaning these complex logic. Thanks For Videos🔥🔥🔥
You genius. I hope you like teaching because we all want more
You did an amazing job explaining this, bravo my good sir!! A like and a sub right here all day!!
Brilliant step by step build up to higher order function usage. Thanks do much
It was really easy to understand the concept in the manner you taught. Thank you !
Hi Corey, thanks for your videos. It certainly helps me clarify concepts and I appreciate what you are contributing to the community. It all works as an explanation, however there are two errors in your JS code that impact the result. Below is version 1.1. I've added it here so other viewers can see a working example of cube and square would get the expected result. I don't think markdown works here, so hopefully other viewers will be able to understand the code in this format.
```
function cube(x){
return x * x * x;
}
function square(x){
return x * x;
}
function my_map(func, arg_list){
result = [];
//for(var i = 1; i
I got here 6 years late... amazing videos
Made me understand first class functions, thank you Corey.
Another use case is to allow a user to select what type of algorithm they want to use for a solver. A generic solver wrapper can then be used to call the algorithm (function) option the user selects at runtime, without having to class everything. Also useful for profiling different functions which perform the same task.
as a new python learner, excellent video +1 and subscribed!
Oh man, I was trying to comprehend closures for a the last week, now thanks to you I understand!
Great videos Corey.
True teacher by heart !!!
Just beautiful. Almost like art. Thank you again Corey
Thank you so much! Your vids are super clear and useful!
Thanks for this explanation of First Class Functions and the examples provided. It also helped me understand the map function better.
Great, thank you very much! I've been using this without knowing the term, it's really helpful to see it on a easy to understand language like python, i saw this on class but the examples were done with a functional programming and for someone that has only been in procedural programming, it was really confusing
You are a light in the dark. Thank you
Hi, I've started to learn with You this year. You do a lot for other people . In this not easy time develop skills, and learning is the one thing which so meaningfull (sorry for my english, I hope its clear :)it gives hope and enjoy:)The way You speak is perfect, also for people who don't speak english very well.
Finally got it. no wonder so many courses drop the ball at closures, decorators, getters setters. Hard part is seeing the inner is accessed by a variable defined as the call of the outer.
This channel is a treasure. i so much appreciate you. You are awesome.
Such a good teacher! You make things very clear in a very short time :)
Very well explained. Thank you very much. I know a lot of programming languages, but everytime i learn a new one i got the feeling, that the concepts are just "Pointers of C in more complicated". But maybe that's just me :D
Very lucid and the examples made it very clear. Subscribed!
Corey is a great teacher
Very useful Tutorial Corey..Really liked your way of explaining the concepts..
Fantastic video and crystal clear explanation, thanks so much!
As I was reviewing python OOP, I found the Schaferian loop. the "Class & Static method" lesson led to "Decorators" which led to "Closures" and lastly to this "First-class". This will lead back to the first lesson. Till I die.
I felt extremely dumb after watching the video and still not getting the point, but then an idea came up in my head and made this example, where I finally understood. Might help you as well
def custom_sum(first_num):
def wrap(second_num):
print(first_num+second_num)
return wrap
two_plus_something = custom_sum(2)
two_plus_something(5)
two_plus_something(10)
two_plus_something(20)
output:
7
12
22
I feel comfortable to think like that-> the upper function creates a template for the inner function which then works on variable over the template to produce output.
Nice side by side video ! Both are my favorite languages ! Thanks for sharing!
I started with python beginners, tutorial #8 on Functions, then Classes.. in order to learn decorators I needed to learn closures.. I have to go back to beginners tutorial #9 at some point :D Thank you so much for amazing lectures...
What a fantastic explanation
very useful, finally got this thing clear.
thank god, another programmer from the south
I appreciate your work, you're awesome.
Do what you do and help others, because you're doing it great.
Big fan of your tutorials, very well done and very organized.
I would like you to point to an error in your javascript code at 6:27. The error you got can be resolved by adding arg_list[i]) not i to the func() as below:
function my_map(func, arg_list){
result = [];
for(var i = 0; i < arg_list.length; i++){
result.push(func(arg_list[i]));
}
return result;
}
The fix you did will only work if the arg_list is starting with 1 and incrementing by 1. Because you will always operate on the index numbers not the item in that index.
Hey Corey, it would be great if you add these two videos (First-Class Functions, Closures ) into a Python playlist (after Function video). It would be perfect continue and flow in that playlist. You have the best Python tuts in youtube (I guess not only in youtube)
A very good example.
Thank you very much Corey, very good explanation and examples!
Love these videos ... I see at 04:14, you looked to demonstrate that you can pass a function to another function as an argument. But, you already demonstrated that with the print() function. But the map() function reinforced the idea ... btw, you’re presentation of material is perfect - not too slow, not too much. Very very well demonstrated too. Nice teaching style.
this video solved many doubts, from map to first class function to closures and I just realised at 11:00 you can use lambda function instead of wrap_text
first of all THANKS sir.
I have learned a lot.
One word, I have for you Corey! Just brilliant!
Thank you so much Corey, this is really great video. I've only seen this one from you but definitely I am going to check more of your Python videos. If others are also as good as this one, I will support you, you have my word :) . Thanks again.
Another good example of passing a function reference is the compare function as an argument in most (all?) sort functions. The compare done in a sort is data or result-order dependent and has too be supplied by the programmer.
Assign function to variable: 1:22
Function as variables: 3:48
Return functions: 7:28
Useful example of returning function: 10:51
I feel like I have come too far.😀
Thank you Corey. You teach so well.