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

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

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

FavoriteLoadingAdd to favorites

In this Python Programming Tutorial, we will be learning about iterators and iterables. There is a lot of confusion around these terms and exactly what they mean. We’re also going to learn how to make an object ourselves that is both an iterable and an iterator. This video isn’t only about understanding these definitions. It’s also about understanding the concepts of iterators so that you can write better code. Understanding these underlying concepts is going to help you write code that is more efficient and will also help you see solutions to certain problems in a way you might not have thought of before. So with that said, let’s get started…

The code from this video can be found at:

Coding Problem for This Video:

Object-Oriented Series:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-06-16T19:51:41+00:00June 16th, 2019|Python Video Tutorials|48 Comments

48 Comments

  1. Sravan Kumar June 16, 2019 at 7:51 pm - Reply

    Very nice explanation

  2. DJTripleThreat78 June 16, 2019 at 7:51 pm - Reply

    Think of it like this: A lock is lockable and unlockable but only a key locks (over) and unlocks (over) a lock.

  3. Bharat Sachdev June 16, 2019 at 7:51 pm - Reply

    Wonderful teacher. Clear precise and best..

  4. Bharat Sachdev June 16, 2019 at 7:51 pm - Reply

    Which ide is this?

  5. McStabbyPantsジェイソン June 16, 2019 at 7:51 pm - Reply

    So python lists are singly linked lists! Awesome! Thanks for this and the tutorials on generators. I purchased a python book but it never delved into the material as deeply as what I wanted. Thanks.

  6. Mario Roberts June 16, 2019 at 7:51 pm - Reply

    👊🏽

  7. Avichal Chadha June 16, 2019 at 7:51 pm - Reply

    great tut

  8. Mike Lisanke June 16, 2019 at 7:51 pm - Reply

    Corey, Liked your video and thought it was instructive but you left a question on the table. You said that an iterable object can be looped over, and has a dunder _next_ method… but later showed us how to create a generator which uses a yield. You say (as do many) that they like the form of a generator object (rather than the programmer maintaining the stateful mechanism for python) BUT you didn't Say IF the generator object Was considered an iterable object… obviously you showed us looping but does it have a __next__() method? Just a piece of the pie missing which I thought would have added to the story. Thanks again, Mike

  9. Daniel Weikert June 16, 2019 at 7:51 pm - Reply

    Great video. Could you elaborate why we need the def__iter__(self) which only returns self in the iterator class?

  10. Ramkrushna Bolewar June 16, 2019 at 7:51 pm - Reply

    Hi… can you make a video on dependency injection container in python.. thank you

  11. Ruggero Piazza June 16, 2019 at 7:51 pm - Reply

    Does anyone know what font is that?

  12. Misha June 16, 2019 at 7:51 pm - Reply

    Thank you for such a profound explanation!

  13. Xaver Xassnytz June 16, 2019 at 7:51 pm - Reply

    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

  14. Duc Deur June 16, 2019 at 7:51 pm - Reply

    is iter() a class in python?

  15. Paul Frankovich June 16, 2019 at 7:51 pm - Reply

    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?

  16. Ryan Feero June 16, 2019 at 7:51 pm - Reply

    You seriously teach this stuff better than anyone I've found. Thank you so much!

  17. Murmad Man June 16, 2019 at 7:51 pm - Reply

    one try statement keeps looping through like a for loop
    can only go forward in iteration
    9:43 template

  18. akil eashwar June 16, 2019 at 7:51 pm - Reply

    Hi can you please make video on metaclass

  19. Rawle Springer June 16, 2019 at 7:51 pm - Reply

    wow you certainly have a gift for teaching…

  20. tun kyi June 16, 2019 at 7:51 pm - Reply

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

  21. Now Or Never June 16, 2019 at 7:51 pm - Reply

    Thanks

  22. zaphbeeblebrox June 16, 2019 at 7:51 pm - Reply

    For the longest time, I thought it was "irritable" and "irritater". 😉

  23. Aman Ranjan verma June 16, 2019 at 7:51 pm - Reply

    What ide are you using?

  24. Shanmuga Raj June 16, 2019 at 7:51 pm - Reply

    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.

  25. Dev June 16, 2019 at 7:51 pm - Reply

    Correction at 1:38 Corey said "Loops aren't the only thing that we can loop over " but he meant "Lists aren't the only thing that we can loop over "

  26. Adam Obaid June 16, 2019 at 7:51 pm - Reply

    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!

  27. Bon Bon June 16, 2019 at 7:51 pm - Reply

    Is there a way to position the iterator somewhere in the middle of the list to begin with? Or reset it without recreating it? Or check whether we're at the end of the list already instead of waiting for the code to crash?

  28. zalazalaza June 16, 2019 at 7:51 pm - Reply

    my objects do not have the "__next__" double underscore method. But they do have a "next" method without the underscores.
    using python v3.6. anyone know the reason for this?

  29. Lex Giezen June 16, 2019 at 7:51 pm - Reply

    Perfectly pitched overview. Thank you.

  30. Utsav Jolapara June 16, 2019 at 7:51 pm - Reply

    Proper good job mate.

  31. Beacon Becay June 16, 2019 at 7:51 pm - Reply

    OMG! Stopped the infinite loop right at my password: 965738!

  32. Alexander William June 16, 2019 at 7:51 pm - Reply

    Thanks Corey

  33. Erwin Gutowitz June 16, 2019 at 7:51 pm - Reply

    Great! Love it when you look under the hood a bit.

  34. Alan Wagoner June 16, 2019 at 7:51 pm - Reply

    Very nice Corey! Thank you!

  35. Lowzenza June 16, 2019 at 7:51 pm - Reply

    Are there videos on the pandas module for python in your channel? Or any plans for it?

  36. Ajith S June 16, 2019 at 7:51 pm - Reply

    Why do we need to use current = start in my_range function?

    Any reason to assign current variable there?

    def range_iter(start,end):
    while start < end:
    yield start
    start += 1

    x = range_iter(1,10)

    for num in x:
    print num

  37. lokesh kumar June 16, 2019 at 7:51 pm - Reply

    Had a long time issue in understanding this concept. You, Corey has always made easy to understand. Can you please make a series on selenium in python.

  38. mahesh kokare June 16, 2019 at 7:51 pm - Reply

    Corey Schafer … U are the only Foreign Youtube, Instructor of Python whom i Follow. Your Videos contains information multifolds 10 which we get from any other video.. I am Surprised how do u do this…You make Sound Python Like Childs Play … Hats off to u … Expecting Machine Learning from You. That could be the Internet Breaker Videos of Yours

  39. jytjfgjfgj June 16, 2019 at 7:51 pm - Reply

    Corey I love your videos but your voice is a little low. Also can you make a series about PySide 2?

  40. Hynek Hrabík June 16, 2019 at 7:51 pm - Reply

    14:19 – I don't understand the for loop. We created the object nums which is instance of class myRange. Fine but how on earth does the loop call the function _next_ nine times to return the current variable?

  41. HardCore June 16, 2019 at 7:51 pm - Reply

    best python instructor ever

  42. Casey McCray June 16, 2019 at 7:51 pm - Reply

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

  43. Sagar Bodapati June 16, 2019 at 7:51 pm - Reply

    Thanks for the nice video. Someday I hope to see a tutorial on memory profiling.

  44. Aaryan Moin June 16, 2019 at 7:51 pm - Reply

    How is yield different from return

  45. Shahzeb Afroze June 16, 2019 at 7:51 pm - Reply

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

  46. Todd Carney June 16, 2019 at 7:51 pm - Reply

    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?

  47. Albert Dugba June 16, 2019 at 7:51 pm - Reply

    You're definitely the best python instructor on YouTube 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

  48. halim 18 June 16, 2019 at 7:51 pm - Reply

    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

Leave A Comment

*