Programming Terms: First-Class Functions

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 480

  • @kickbuttowsk2i
    @kickbuttowsk2i 4 года назад +559

    Rabbit hole: Classes > Decorators > Closures > First-Class Functions. Thank you Corey

    • @tahsintariq8757
      @tahsintariq8757 4 года назад +38

      For me it was Multiprocessing > Threading > Decorators > Closures > First-Class Functions. Great videos!!

    • @soupnoodles
      @soupnoodles 3 года назад +9

      this is exactly what happened rip

    • @HerambLonkar95
      @HerambLonkar95 3 года назад +2

      For me as well

    • @konyi449
      @konyi449 3 года назад +1

      @@tahsintariq8757 me too

    • @sundaymanali5854
      @sundaymanali5854 3 года назад +1

      yeah wtf lol

  • @darthvador3699
    @darthvador3699 8 лет назад +1386

    *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.

    • @coreyms
      @coreyms  8 лет назад +210

      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.

    • @berryblast3930
      @berryblast3930 8 лет назад +14

      same

    • @darrenandveronica
      @darrenandveronica 7 лет назад +105

      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

    • @zbzb-ic1sr
      @zbzb-ic1sr 7 лет назад +12

      You're Darth Vader, you should know how to code.

    • @hailstress
      @hailstress 7 лет назад +7

      Same scenario over here.

  • @FamilyGuySweden
    @FamilyGuySweden 6 лет назад +187

    I ended up here because I was watching "Python OOP Tutorial 3: classmethods and staticmethods". Thats a chain invocation of tutorials :D:D:D

  • @ledosilverknight4619
    @ledosilverknight4619 6 лет назад +48

    Corey is a beast at teaching people how to code.

  • @kelleywooten1712
    @kelleywooten1712 4 года назад +40

    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

    • @sabbywins
      @sabbywins Год назад +2

      Woooooo Go Kelley!

  • @colemanj64
    @colemanj64 7 лет назад +49

    I've watched half a dozen videos on Python first class functions but only now, after watching this from Corey, do I understand it.

  • @akshgpt7
    @akshgpt7 4 года назад +21

    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!

  • @alperakbash
    @alperakbash 5 лет назад +23

    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.

  • @Deepak-yz5zl
    @Deepak-yz5zl 2 года назад +12

    Some tutorials never gets old! Such a great teacher

  • @thsdsyt
    @thsdsyt 4 года назад +6

    This guy really knows how to explain programming languages. Amazing!

  • @classik305
    @classik305 6 лет назад +15

    you're a freak of nature, my guy. You just took me to that next Python level. THANK YOU!!

  • @dgbene1
    @dgbene1 6 лет назад +9

    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.

    • @melonelonm6074
      @melonelonm6074 5 лет назад

      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 ?

  • @eugen3775
    @eugen3775 7 лет назад +16

    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

  • @rishabhmishra2908
    @rishabhmishra2908 2 года назад +1

    finally found someone who got me crystal cleared with first class functions, closures and decorators......
    good work Corey !

  • @shashanknegi7861
    @shashanknegi7861 3 года назад

    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

  • @princeofxane
    @princeofxane 5 лет назад +1

    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.

  • @PunjabiDuoVlogs
    @PunjabiDuoVlogs 5 лет назад +2

    I have never seen anything explained anywhere just like you did. THANK YOU. You are really the BEST teacher.

  • @Colstonewall
    @Colstonewall 8 лет назад +11

    Very nice. Well thought out examples for a topic that's rarely covered.

  • @artihlec
    @artihlec 7 лет назад +53

    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.

    • @coreyms
      @coreyms  6 лет назад +23

      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!

    • @snoopyjc
      @snoopyjc 5 лет назад +3

      I was about to point out the same thing

    • @marflage
      @marflage 4 года назад

      Or you could use For...of, or For...each functions.

  • @andresvodopivec5950
    @andresvodopivec5950 5 лет назад +2

    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!

  • @masterbat8953
    @masterbat8953 4 года назад +1

    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

  • @iamviccckkk
    @iamviccckkk Год назад +1

    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

  • @draosf
    @draosf Год назад +1

    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.

  • @oppaarif3975
    @oppaarif3975 2 года назад +1

    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.

  • @ManzoorHussain-gz1vk
    @ManzoorHussain-gz1vk 2 года назад +1

    I love the ways you teach. My words are not enough to explain how much I love your teaching style and high level content.

  • @abhilashkaluwala
    @abhilashkaluwala 4 года назад

    i was struggling to understand this concept, this is the BEST EXPLAINATION ON THE INTERNET.

  • @temporary_variable
    @temporary_variable 5 лет назад +1

    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.

  • @ashwinsingh1325
    @ashwinsingh1325 5 лет назад +2

    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.

  • @joxa6119
    @joxa6119 9 месяцев назад

    The series is super helpful for a person like me that has no computer science background.

  • @KhattyDT
    @KhattyDT Год назад

    Been watching a lot of tutorial videos but yours is the best! Simple and straight to the point! Thanks a lot.

  • @pythonicd1239
    @pythonicd1239 3 года назад +3

    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.

  • @meatyout
    @meatyout 5 лет назад +1

    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

  • @mau_lopez
    @mau_lopez 5 лет назад +3

    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!

  • @aashayamballi
    @aashayamballi 5 лет назад +5

    Man! Corey you're really great at explaining things, my mind actually blown... Thank you so much!

  • @mahmoudreda1083
    @mahmoudreda1083 4 года назад

    classmethods and staticmethods >>> Decorators >>> Closures >>> First-Class Functions.
    Keep the GOOD work Sir!

  • @cutefunnyanimals5441
    @cutefunnyanimals5441 Год назад

    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!

  • @youcefguichi3132
    @youcefguichi3132 2 года назад

    almost 2023 and still very helpful, thanks a lot for your tutourials

  • @marting9771
    @marting9771 3 года назад

    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!

  • @TheFallibleFiend
    @TheFallibleFiend 6 лет назад

    I especially appreciate your going through the python and javascript together.

  • @bermetumarova4683
    @bermetumarova4683 2 года назад +1

    Thanks, finally I understood what is first class functions.

  • @andresa249
    @andresa249 7 лет назад

    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.

  • @Descart330
    @Descart330 Год назад +1

    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.

  • @heshankumarasinghe3159
    @heshankumarasinghe3159 4 года назад

    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.

  • @Glashome
    @Glashome 5 лет назад +1

    great example for the utility of returning a function. Really helpful

  • @cryptotv3013
    @cryptotv3013 2 года назад

    Awesome explanation video for both languages, I was struggling past one week on this topic watching more videos finally figured out all.

  • @simonaugustocarroz4447
    @simonaugustocarroz4447 3 года назад +1

    Well explained and to the point, i cant believe this guy is real

  • @remedyiq8034
    @remedyiq8034 Год назад

    Best videos on youtube. The way you explain concepts are simply amazing

  • @hubertcombomarketing2693
    @hubertcombomarketing2693 4 года назад +8

    You're amazing guy Corey. Thank You very much for Your work.

  • @YeekyYeeky
    @YeekyYeeky 3 года назад

    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

  • @millaw.1718
    @millaw.1718 5 лет назад +3

    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!

  • @bernoulli9047
    @bernoulli9047 4 года назад +2

    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.

  • @dequationblog
    @dequationblog 5 лет назад +1

    Fast becoming a fan here, Mr. Schafer. A+ on the didactics and presentation.

  • @meatyout
    @meatyout 5 лет назад

    +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.

  • @glitchedgitz
    @glitchedgitz 3 года назад

    This guy is beast at explaning these complex logic. Thanks For Videos🔥🔥🔥

  • @oadams8
    @oadams8 4 года назад

    You genius. I hope you like teaching because we all want more

  • @adrianayon5513
    @adrianayon5513 2 года назад +2

    You did an amazing job explaining this, bravo my good sir!! A like and a sub right here all day!!

  • @basu_104
    @basu_104 Год назад

    Brilliant step by step build up to higher order function usage. Thanks do much

  • @ayushgupta1881
    @ayushgupta1881 2 года назад

    It was really easy to understand the concept in the manner you taught. Thank you !

  • @iautomatecloud9305
    @iautomatecloud9305 7 лет назад

    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

  • @fabiodbr
    @fabiodbr Год назад +1

    I got here 6 years late... amazing videos

  • @karsten600
    @karsten600 6 лет назад +2

    Made me understand first class functions, thank you Corey.

  • @Achrononmaster
    @Achrononmaster 5 лет назад +1

    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.

  • @qtran101
    @qtran101 6 лет назад +2

    as a new python learner, excellent video +1 and subscribed!

  • @salman.1st
    @salman.1st 7 лет назад +2

    Oh man, I was trying to comprehend closures for a the last week, now thanks to you I understand!

  • @DeTeK-Dennis
    @DeTeK-Dennis 7 лет назад +2

    Great videos Corey.
    True teacher by heart !!!

  • @nriezedichisom1676
    @nriezedichisom1676 Год назад

    Just beautiful. Almost like art. Thank you again Corey

  • @AriaHarmony
    @AriaHarmony 6 лет назад +3

    Thank you so much! Your vids are super clear and useful!

  • @ChaosArtist
    @ChaosArtist 3 года назад

    Thanks for this explanation of First Class Functions and the examples provided. It also helped me understand the map function better.

  • @tomaspinto3833
    @tomaspinto3833 6 лет назад +2

    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

  • @SeaTaj
    @SeaTaj 2 года назад

    You are a light in the dark. Thank you

  • @evergreen7673
    @evergreen7673 4 года назад

    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.

  • @parmachine470
    @parmachine470 3 года назад

    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.

  • @mohammadalaaelghamry8010
    @mohammadalaaelghamry8010 Год назад

    This channel is a treasure. i so much appreciate you. You are awesome.

  • @gusirity
    @gusirity 8 лет назад +1

    Such a good teacher! You make things very clear in a very short time :)

  • @STFU665
    @STFU665 2 года назад

    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

  • @aliyaqoob8779
    @aliyaqoob8779 5 лет назад +1

    Very lucid and the examples made it very clear. Subscribed!

  • @kneelesh48
    @kneelesh48 4 года назад

    Corey is a great teacher

  • @PrinceKumar-um8mw
    @PrinceKumar-um8mw 7 лет назад +1

    Very useful Tutorial Corey..Really liked your way of explaining the concepts..

  • @WarrenMarshallBiz
    @WarrenMarshallBiz 5 лет назад +1

    Fantastic video and crystal clear explanation, thanks so much!

  • @nhwhn
    @nhwhn 3 года назад

    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.

  • @alberkulicka954
    @alberkulicka954 Год назад

    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

  • @SabbirAhmed-ym4yf
    @SabbirAhmed-ym4yf 6 лет назад

    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.

  • @tradertube
    @tradertube 7 лет назад

    Nice side by side video ! Both are my favorite languages ! Thanks for sharing!

  • @cigdemylmaz1532
    @cigdemylmaz1532 5 месяцев назад

    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...

  • @gururajchadaga
    @gururajchadaga 4 года назад +1

    What a fantastic explanation

  • @howardzhu2298
    @howardzhu2298 5 лет назад +1

    very useful, finally got this thing clear.

  • @calebpennington5310
    @calebpennington5310 2 года назад

    thank god, another programmer from the south

  • @angelikaprzeliorz8325
    @angelikaprzeliorz8325 4 года назад

    I appreciate your work, you're awesome.
    Do what you do and help others, because you're doing it great.

  • @AhmadShrif
    @AhmadShrif 4 года назад

    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.

  • @ShynggysZ
    @ShynggysZ 4 года назад +2

    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)

  • @ramasubramanianduraraj8013
    @ramasubramanianduraraj8013 4 года назад +1

    A very good example.

  • @alejandronieto576
    @alejandronieto576 2 года назад

    Thank you very much Corey, very good explanation and examples!

  • @richardwalters9249
    @richardwalters9249 4 года назад

    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.

  • @manjeetrohilla7414
    @manjeetrohilla7414 3 года назад

    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

  • @jonathanpaule3602
    @jonathanpaule3602 4 года назад +1

    first of all THANKS sir.
    I have learned a lot.

  • @Vish_27-v8x
    @Vish_27-v8x Год назад

    One word, I have for you Corey! Just brilliant!

  • @20dorko
    @20dorko 7 лет назад +1

    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.

  • @dzittin
    @dzittin 4 года назад

    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.

  • @NoName-ef2gv
    @NoName-ef2gv 4 года назад

    Assign function to variable: 1:22
    Function as variables: 3:48
    Return functions: 7:28
    Useful example of returning function: 10:51

  • @shashanksharma7242
    @shashanksharma7242 4 года назад +1

    I feel like I have come too far.😀
    Thank you Corey. You teach so well.