Python Tutorial - 21. Iterators

preview_player
Показать описание

In this python tutorial, we will get a basic understanding of “Iterators”, how to create own Iterators using class, use of Iterators through examples, what are reversed Iterators, how to implement own Iterators class and what is Iter method.

Topics that are covered in this Python Video:
0:00 what is Iterators?
0:52 How for loop works internally
3:15 Examples of Iterators
3:48 reversed Iterators
4:46 Implement own Iterators class
6:00 Define iter method

Next Video:

Рекомендации по теме
Комментарии
Автор

Sir despite of your great explanations/teachings, I find a great sense of generosity and humbleness in your voice. Ishvar tamaru khoob khoob kalyan kare, evi mari ishvar ne tamara maate vinanti.

charmindesai
Автор

I think that the problem is that you are just raising the stop iterating when se lenght = = index, but you actually should do so when index == lenght - 1, since index count from zero and lenght is the number of elements (when you are in the last element of your loop, index = 3, not 4)

JNetoMenoci
Автор

Ok, for everyone who come here...I wanna say it is best video for clearing iterator concept
P.S. If anyone need a help to understand this code than ask me

Автор

I have been going through your videos on python tutorial. Basics well explained, really helpful, thanks for coming up with this tutorial. Can you please upload a tutorial for Full Stack Web Development (using Python, MySql and HTML) following the MVC architecture without any framework (like Django, Web2py etc) ? It will be really helpful to understand Python on an advanced level.
P.S: The BG music ain't that bad.

debikadandapat
Автор

why not just call r.next ()? the iter function has me confused. So you create an insrance of remotecontrol called r and then pass the instance back to its self? Please explain, i would greatly appreciate it.

rthu
Автор

Explanation is excellent Sir.
Sir, I think the error is because you have written "class RemoteControl():" which is wrong, we should write "class RemoteControl:". Parenthesis won't be there when we write class name.

TheDufferr
Автор

You can improve your custom RemoteControl iterator in many ways. First, setting the first valid index at value 0 instead of -1 results in cleaner code (for the next method) not to mention that -1 as a first index is misleading for -1 being a valid index in Python. Second, you don't need to call your iterator by running the iter standard function, you can directly call the next function on it. Third and most importantly : your custom iterator is not really a custom one, it's equivalent to iter(["HBO", "cnn", "abc", "espn"]) and by this we lose all the interest for an iterator (an iterator doesn't store).

elastica
Автор

Could you please explain why we need "__" in the class for iter and next method? why do we need the iter method at all here?

sandeepv
Автор

hey bro u are really really OSOM....thank bro...

wasit-shafi
Автор

Why the message errors in red along with output.

nuruljanah
Автор

Please, can you send tutorial for class object as decorator

nirbhaiuppal
Автор

Sir, I dont understand why the iter method returns the self (object of the class)

SmitPatel-hshv
Автор

can you tell me which delimiter is used in iter method by default here comma is used. but in other situations?

krishnanadagoudra
Автор

HI i just have one question, to call a function from a class should we not use the object instance. Example in your code why did u not use r.iter() and r.next() ??

LailahaillahChannel
Автор

I dont understand the self.index == len(self.channels), can you explain how this works?

oping
Автор

the for loop internally calls __iter__ method and returns the list_iterator object .. but also is it the case that the __iter__ method further calls the __next__ method automatically??

tusharsibal
Автор

Did anyone understand why the __iter__() method return the object of the class, what is it doing? I have gone through many tutorials but so far no luck

SmitPatel-hshv
Автор

Hi..When i am executing this code in Python 2.7 ..getting this error[ print next(itr)
TypeError: instance has no next() when i execute with print itr.__next__() then only i got o/p..I am confuse help me

vvkkumar
Автор

a="string"
dir(a) --> Gives an output which containt __iter__ but when we use next(a) it throws an error saying TypeError: 'str' object is not an iterator.

Any inputs on this

varunpratapsingh
Автор

how is self.index =4 when index starts from 0 ? I am confused.

ArijitBiswasdotcom