Python Tutorial: Iterators and Iterables - What Are They and How Do They Work?

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

ความคิดเห็น • 317

  • @gioxc88
    @gioxc88 6 ปีที่แล้ว +457

    best python instructor ever

  • @aman0509
    @aman0509 4 ปีที่แล้ว +14

    Closure and Decorator tutorial of yours was my first experience and I am telling you, you have explained it in such a good way that I cannot forget it ever. I am not being dramatic but your explanation method is magical. When I am learning any concept, there are things which are buried inside my mind and but it cannot get out because I feel confused and also nobody talking about the same or have that kind of explaining system as yours. It's like you are connected to my mind.
    So, Thank You Very Much!! God Bless You!!

    • @coreyms
      @coreyms  4 ปีที่แล้ว

      Thanks! Glad to hear that

  • @judeleon8485
    @judeleon8485 4 ปีที่แล้ว +23

    Corey, you're awesome! You always make my day. Anytime I'm in need need of a lesson on any python topic, your channel is always my first port of call, to see if you have it. You always know how to make it sink in so well. Thanks

  • @WaldoTheWombat
    @WaldoTheWombat ปีที่แล้ว +12

    1. In Python, an object can be called an "iterable" if it has the dunder method __iter__ which should return an iterator and an iterator is an object that has the method __next__.
    2. __iter__ is a method that a python list has.
    3. By performing the for loop on the list, python invokes that list's __iter__ method which returns an iterator that we can loop over.
    we can do next(mylist.__iter__()) which invokes the iterator's __next__ method or call or invoke it directly: mylist.__iter__().__next__()
    we can also do next(iter(mylist))
    "Generators are iterators as well, but the duder iter and duner next methods are created automatically."

  • @veeplusvee
    @veeplusvee 2 ปีที่แล้ว +5

    Corey, Simply you are the best when it comes to making someone understand the concept. Unless someone understands the concept, it is very difficult to write codes that are lot efficient and at the same time very easy to understand/read. I wish everyone who makes video on programing follows a similar template for teaching. Thanks a lot.

  • @baqirhusain5652
    @baqirhusain5652 4 ปีที่แล้ว +7

    Oh My God....I didn't know learning python can be this addictive.... Thank you sooooooooooooooo muchhhh

  • @beginner_bro
    @beginner_bro 2 หลายเดือนก่อน +1

    This is your first video I am watching. And this single video forced me to subscribe your channel. Great job man

  • @techcode_man
    @techcode_man 5 ปีที่แล้ว +18

    Corey, Thank you for explaining this so well and simple. I have been using both iterators and iterables for while, now it makes a lot of sense.

  • @emmanuel5566
    @emmanuel5566 4 ปีที่แล้ว

    dude.. your voice is so distinct and your explanation is crystal clear.
    if I can't find something on StackOverflow or if I'm learning a new concept in python, your channel is THE resource for me. Great content.
    Thank you for keeping it free.

  • @halim1885
    @halim1885 6 ปีที่แล้ว +1

    i've tried a lot of teachers in order to make progress and non of them works , you are the best sir i advise everyone want to learn python to watch your serie

  • @venkatdevireddy650
    @venkatdevireddy650 6 ปีที่แล้ว +13

    Ur videos are awesome Corey I have been watching all ur videos... please make an video on SYS module as well as XML parsing...I have got bunch of videos from you tube none other videos are up to the mark as u...ur explanation in any concept is at peeks no body beats u... thanks a lot

  • @shahzebafroze4093
    @shahzebafroze4093 6 ปีที่แล้ว +106

    Thank you for making these awesome videos!! Goal after graduation: support your channel.

    • @Worldofdave
      @Worldofdave 3 ปีที่แล้ว +3

      Did you by now :D

  • @pedrocontrerasavendano8578
    @pedrocontrerasavendano8578 6 ปีที่แล้ว +7

    Precise, coherent, well articulated and well structured; good tutorial, thanks

  • @Greenbay-bn3yk
    @Greenbay-bn3yk 3 หลายเดือนก่อน +1

    Old but Gold. What an excellent explanation

  • @albertdugba
    @albertdugba 6 ปีที่แล้ว

    You're definitely the best python instructor on TH-cam by far...But some of us will appreciate it you could maximise the screen size we can clearly see instead of straining our eye which is probably not the best. Thank you

  • @RuslanSheffchenko
    @RuslanSheffchenko 9 หลายเดือนก่อน

    thank you so much for this video. I've been queering bing chat and bard chat for a couple of hours on the iterable and iterator topics but none of them managed to explain the stuff to me in a so clear way that you did.

  • @TonyFlexPromo
    @TonyFlexPromo 6 ปีที่แล้ว +3

    At first i was totally scared of iterators. Next i took a study and understood how do they work and why they are used. Next i wrote some iterators and generators on my own. Then i got a question about iterators on job interview and i was one of few people who actually answered the question (as they said later). Now i really love this feature of python and this is kinda future of it because whole async thing is based on yield thing.
    Thank you for videos! I continue to learn a lot from you!

  • @chuckles8519
    @chuckles8519 2 ปีที่แล้ว

    You have a very clear teaching style - a very valuable talent to have!

  • @aakashrane8360
    @aakashrane8360 4 ปีที่แล้ว

    Just half done with the video and just want to say WOW!!! Corey, try writing your own python book.

  • @danielkamau8436
    @danielkamau8436 3 ปีที่แล้ว +1

    good_tutor = "Corey Schafer"
    while True[good_tutor]:
    next(good_tutor)
    #looping forever sir thanks for expensive, but free endless knowledge. go beyond.

  • @swapnilp4629
    @swapnilp4629 2 ปีที่แล้ว

    looks I found this bit late since this was published but trust me Your are the Best . I have gone through so many videos but the way you explain and demonstrate is AWESOME!! Keep it up :) All the best...

  • @zyenapz
    @zyenapz 3 ปีที่แล้ว

    Thanks for the straightforward and non-verbose explanation!

  • @sg8581
    @sg8581 ปีที่แล้ว

    One of the best explanations on iterators. Thanks a ton!

  • @Matharendre
    @Matharendre ปีที่แล้ว

    It really sums up the concepts in a concise but precise way.
    Thank you a lot for this!

  • @rajgiriyt8494
    @rajgiriyt8494 3 ปีที่แล้ว

    explaining each and every steps. where were you before. please do not leave this way of teaching. we beginners needs you

  • @xaverxassnytz2746
    @xaverxassnytz2746 5 ปีที่แล้ว +1

    very good explanation in this and generators video (also watched your other videos) - thanks to Corey
    coming from old languages like Fortran, Cobol, Pascal and I just began learning python 3 months ago and this videos helped me a lot to get a basic knowledge

  • @AshisRaj
    @AshisRaj 2 ปีที่แล้ว +1

    My search ends here. Excellent explanation

  • @calebthompson1037
    @calebthompson1037 2 ปีที่แล้ว

    Classes in school should be like this a hyperlink to what you dont understand included. 💯

  • @shashishekhar----
    @shashishekhar---- ปีที่แล้ว +1

    Thank you so much Corey, much appreciated how helpful this(these) videos are, just thank you 👍

  • @DioD3
    @DioD3 4 ปีที่แล้ว +1

    Excellent video. Thank you! You are my favorite programing(python) teacher.

  • @panditnandlalpatherwali5979
    @panditnandlalpatherwali5979 6 ปีที่แล้ว +5

    Corey I am big fan of you videos, kindly post the video on pytest

  • @DevinderKumar
    @DevinderKumar 4 ปีที่แล้ว +1

    Super, very useful lesson. Great stuff in a shortest possible time. Thanks a lot.

  • @marioestrada2233
    @marioestrada2233 3 ปีที่แล้ว +1

    Many thanks man! You are truly great at teaching! Please continue with this awesome work

  • @hubertcombomarketing2693
    @hubertcombomarketing2693 4 ปีที่แล้ว +1

    Great Python Iterators and Iterables Tutorial. Thank You.

  • @TheGroundskeeper
    @TheGroundskeeper 2 ปีที่แล้ว

    So, weird moment for me. I like to go back over the parts where my ADHD started to go crazy, and when you said "Now remember I said iterators are objects with a state that..." is when I went to back up a few minutes to get back on track. When I randomly let go, you said "iterators are objects with a state that...", so I weirded out and instantly now remember this rule. I have absorbed your power. There can only be One.

  • @adamobaid3558
    @adamobaid3558 5 ปีที่แล้ว +2

    Thank you, you are great instructor. These videos are awesome and have helped me so much. I will make a contribution when I get hired soon!

  •  2 ปีที่แล้ว

    A video on unit testing iterables, generators, and, unit testing functions that consume iterable objects would be great.

  • @MagnusAnand
    @MagnusAnand 5 ปีที่แล้ว +2

    This video is amazing! Your teaching skills are top

  • @konstantin6482
    @konstantin6482 5 ปีที่แล้ว +4

    Great video, but I don`t quite get one thing. It seem that at 14:30 when you use a for loop on new object *__next__()* method is somehow called. But there is no reference to it anywhere in the class *Myrange* you`ve just created. I suppose that *__iter__()* method somehow calls it, but how does it exactly work?

  • @MehmetMustafaICER
    @MehmetMustafaICER 4 ปีที่แล้ว +1

    Thank you for this video. It is pretty clear and to-the-point. Well done.

  • @gustavojuantorena
    @gustavojuantorena 2 ปีที่แล้ว

    This video is pure gold!

  • @TheSumanb
    @TheSumanb 3 ปีที่แล้ว

    Thanks a ton ... your way of teaching is one of the best , please keep on posting tutorials on pandas and Numpy or any advanced python topics , thanks

  • @samed3554
    @samed3554 2 ปีที่แล้ว

    Very plain and well explained. Thank you Corey, subbed.

  • @Sabre00
    @Sabre00 5 ปีที่แล้ว

    From the time you mentioned the never ending generator and iterators not being able to be recalled it reminded me of a database auto-increment field.
    Just waiting for the timeseries MatplotLib video.

  • @zhukovmisha
    @zhukovmisha 5 ปีที่แล้ว +4

    Thank you for such a profound explanation!

  • @temilolafamakinwa1626
    @temilolafamakinwa1626 ปีที่แล้ว

    Excellent explanations are always!!

  • @alexandredamiao1365
    @alexandredamiao1365 4 ปีที่แล้ว +1

    Your lectures are amazing! Thank you so much for this!

  • @billykotsos4642
    @billykotsos4642 4 ปีที่แล้ว +1

    Great Tutorial

  • @xlulu464
    @xlulu464 4 ปีที่แล้ว

    finally i can try to understand why for loop is different from while loop. thanks

  • @ThatSic
    @ThatSic 6 ปีที่แล้ว +1

    Great video as always!
    Btw, I think you meant 'generator' instead of 'iterator' at 20:12 when you talked about memory effeciency.

  • @swapneelsahu9440
    @swapneelsahu9440 3 ปีที่แล้ว

    for anyone who doesnt understand why he keeps saying "dunder" before each method names
    , he means to say "DOUBLE UNDERSCORE" iter,next,etc
    *basically instead of saying "DOUBLE UNDERSCORE" each time, he says "dunder" , since its easier to say*
    *D-UNDER* ===> Double UNDERscore

  • @tunkyi7162
    @tunkyi7162 5 ปีที่แล้ว +2

    you are making me clear things up. I gave a like and subscribed to your channel.

  • @jessicabrown1987
    @jessicabrown1987 4 ปีที่แล้ว

    Corey you are the best.

  • @hetalchavan9446
    @hetalchavan9446 4 ปีที่แล้ว +1

    Amazing lecture!Very informative!Already subscribed after seeing this one.

  • @zikomo8913
    @zikomo8913 4 ปีที่แล้ว +1

    Holy shit, even a summary at the end! Can a tutorial get any better than this?

  • @Alex-rw9yj
    @Alex-rw9yj 2 ปีที่แล้ว

    Thank you, man! Very clear and concise.

  • @deojeetsarkar2006
    @deojeetsarkar2006 5 ปีที่แล้ว +1

    this guy's a genius

  • @MauriceWilliams
    @MauriceWilliams 4 ปีที่แล้ว

    Thanks Corey you delivered as usual.

  • @JuanCEOs725
    @JuanCEOs725 ปีที่แล้ว

    Simply the best!

  • @szabikrdev5066
    @szabikrdev5066 2 ปีที่แล้ว

    Cheers man, this was extremely useful piece of content!

  • @JoySenseKO
    @JoySenseKO 29 วันที่ผ่านมา

    You are simply amazing ❤

  • @whoami2091
    @whoami2091 3 ปีที่แล้ว

    You are a king man!

  • @franndyabreu6272
    @franndyabreu6272 6 ปีที่แล้ว +5

    Thank you.

  • @xiaoweidu4667
    @xiaoweidu4667 3 ปีที่แล้ว

    fantastic teacher

  • @AlanWagoner
    @AlanWagoner 5 ปีที่แล้ว +1

    Very nice Corey! Thank you!

  • @amardeepbhowmick3614
    @amardeepbhowmick3614 5 ปีที่แล้ว +1

    Beautiful! Corey you da man!

  • @dibyajyotisahoo3882
    @dibyajyotisahoo3882 4 ปีที่แล้ว +1

    You are the best

  • @mostafaghanem3984
    @mostafaghanem3984 9 หลายเดือนก่อน

    Thank you , you’re the goat

  • @hirunahansaka646
    @hirunahansaka646 7 หลายเดือนก่อน

    thank you very clear your explanation

  • @Karthik_705
    @Karthik_705 หลายเดือนก่อน

    Nice Explanation

  • @veeek8
    @veeek8 2 ปีที่แล้ว

    thanks so much, great explaination

  • @CaptainBravo87
    @CaptainBravo87 ปีที่แล้ว

    Great explanation

  • @gordonlim2322
    @gordonlim2322 4 ปีที่แล้ว +1

    May I ask why then iterable exists if we are have to use iter() to turn it into an iterator for it to be useful.

  • @abhinav9561
    @abhinav9561 2 ปีที่แล้ว

    Thanks Corey!!

  • @tcarney57
    @tcarney57 6 ปีที่แล้ว +1

    Many thanks. Two questions: 1) If we create a class that is a subclass of, say, the List class, we will inherit List's dunder methods, right? So we won't have to manually add __iter__ and __next__ ourselves? and 2) Do you run your narration through some kind of audio speed changer or do you just drink a quadruple espresso before you record?

    • @coreyms
      @coreyms  6 ปีที่แล้ว

      1) That is right, it would inherit those methods. 2) I’m a fast talker haha. Surprisingly, this is me talking on Chamomile tea, so I don’t wanna hear myself after some espresso shots

  • @PyProjects
    @PyProjects 10 หลายเดือนก่อน

    Thanks for the awesome video.
    How do you make your terminal clutter free like that?

  • @sachinchaudhary8251
    @sachinchaudhary8251 2 ปีที่แล้ว

    This guy is amazing. why Corey why. why you stopped uploading videos.

  • @javier144663
    @javier144663 2 ปีที่แล้ว

    I am puzzled as to why the __next__ method works. If I'm at the second to last element the 'current' variable in the __next__ method will take its value. Then what is incremented is self.value, so for the method to work, I understand that 'current' is actually a reference to self.value, and not a hard copy. Thus when incrementing self.value, current is also incremented. If that is so, I wonder if it would be clearer to just increment self.value and then return it already incremented.

  • @isaiahthomas7015
    @isaiahthomas7015 2 ปีที่แล้ว

    How many Iterables can be ran on the background? Would that produce different variables on the original list?

  • @caseymccray3861
    @caseymccray3861 6 ปีที่แล้ว

    Love the idea of a password bruteforcer .
    Please make a video on it

  • @adetunjidaniel5064
    @adetunjidaniel5064 ปีที่แล้ว

    Nice video
    Just out of curiosity, how does an iterable object which isnt a iterator work(since it wont be having the next method in its class definition work).

  • @qrubmeeaz
    @qrubmeeaz 5 ปีที่แล้ว +4

    For the longest time, I thought it was "irritable" and "irritater". ;-)

  • @Amir-English
    @Amir-English 9 หลายเดือนก่อน

    why did you define __iter__ function inside the class MyRange@13:23??
    isn't the __iter__ function a defined magic method already defined in Python??

  • @mvlad7402
    @mvlad7402 5 ปีที่แล้ว +1

    great material

  • @carpediem73
    @carpediem73 3 ปีที่แล้ว

    thanks corey

  • @faressalehi5553
    @faressalehi5553 3 ปีที่แล้ว

    لقد تعلمت منك كثيرا,,, أسأل الله أن يشرح صدرك للإسلام ويدخلك الجنة.

  • @user-qs6dp2fw7q
    @user-qs6dp2fw7q 5 ปีที่แล้ว +1

    Thanks Corey

  • @OfficialDockvulner-qt9mk
    @OfficialDockvulner-qt9mk 5 หลายเดือนก่อน

    nice tutorial!

  • @chelloveck
    @chelloveck 6 ปีที่แล้ว +3

    good, thanks.

  • @malakhassan9816
    @malakhassan9816 4 หลายเดือนก่อน

    Really thank you

  • @linvictor3604
    @linvictor3604 2 ปีที่แล้ว

    Why put a square bracket on the instance around dev_1 ([dev_1]) when pass to mgr_1? I try to remove it but receive a error that TypeError: argument of type 'dev_1 is not iterable. Can help to explain in more detail? Thx!

  • @zodicracker
    @zodicracker ปีที่แล้ว

    when i add that code in iDLE it comes back with Traceback (most recent call last):
    File "C:/Users/lesli/AppData/Local/Programs/Python/Python311/aaa.py", line 10, in
    print(num)
    NameError: name 'num' is not defined. Did you mean: 'nums'? any particular reason why?

  • @wartem
    @wartem 2 ปีที่แล้ว

    Just amazing

  • @darshikaverma9170
    @darshikaverma9170 4 ปีที่แล้ว +1

    Awesome

  • @sravankumar5017
    @sravankumar5017 5 ปีที่แล้ว

    Very nice explanation

  • @aryan7069_
    @aryan7069_ 4 ปีที่แล้ว +1

    very complicated concept

  • @ArunKumar-yb2jn
    @ArunKumar-yb2jn 3 ปีที่แล้ว

    You said you will make your own iterator, but you went on to use built in __next__ method within the class (myRange). How is that making your own iterator? I tried changing function name from __next___ to something else like 'new' and it won't work.

  • @paulfrankovich3085
    @paulfrankovich3085 5 ปีที่แล้ว

    Awesome videos. I’m learning a lot to get proficient with Python. One minor question, why do your 1-10 list stop at 9? Is that by design?

    • @coreyms
      @coreyms  5 ปีที่แล้ว +1

      Yes, ranges are non-inclusive on the upper number in Python. There are several reasons for that, but a bit too much to put into a comment. You can search why and find a lot of reasoning behind it.

    • @paulfrankovich3085
      @paulfrankovich3085 5 ปีที่แล้ว

      Great. Will do! Thanks!

  • @salarghaffarian4914
    @salarghaffarian4914 3 ปีที่แล้ว

    Awesome!

  • @dennisasamoah2213
    @dennisasamoah2213 5 ปีที่แล้ว +1

    Great