Тёмный

#61 Python Tutorial for Beginners | Iterator 

Telusko
Подписаться 2,4 млн
Просмотров 347 тыс.
50% 1

Github :- github.com/nav...

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 284   
@jimmymesa
@jimmymesa 5 лет назад
print(next(values)) prints 1 and also changes the state of the iterator after which num = 2. So the for loop will print the numbers from 2 to 10.
@swethasundaram04
@swethasundaram04 3 года назад
The raise keyword is used to raise an exception. You can define what kind of error to raise(here its StopIteration).
@shivasaiprasadakula7386
@shivasaiprasadakula7386 3 года назад
I was made mistake while Entering the code like (stopiteration...but the s should be caps ) after watching your comment I entered Caps S Now I Got the correct code without error thanks... 👍🥰
@Shrishivbharat
@Shrishivbharat 5 лет назад
Sir, when will you make videos on tikinter and other python GUI?
@sriram9786
@sriram9786 4 года назад
sir can you put another vedio on this. i dint understand completely.
@BryceDoesLife
@BryceDoesLife 5 лет назад
This was exactly what I needed thank you
@bhu1868
@bhu1868 3 года назад
seems like you are an music artist, do u use python in music some way?
@anoshkaniskar1482
@anoshkaniskar1482 3 года назад
The when you say Iterators. How cool is that..
@omkarmore7017
@omkarmore7017 4 года назад
Can someone or Navin tell me this that why are we not converting that TopTen class object 'values' to iterator object i.e like values = iter(values) As you are not creating iterator object in last example how is __iter__ method getting called or how is it working without it. As far as i know if we create an object of class only init method gets performed without calling. Please Help me with this. And Cheers to your work Navin. Thank you very much
@mohammadziauddin6270
@mohammadziauddin6270 Год назад
There was an indentation error at return val thats why its repeating., remove 1 space before return.
@startjourney8631
@startjourney8631 3 года назад
Dil se dhanywaad🙏✌️🤗
@santhoshbyri125
@santhoshbyri125 4 года назад
break also possible
@alaapsarkar
@alaapsarkar 3 года назад
print statement prints 1 and the for loop prints 2, 3, 4,..., 10
@venkatratnam4891
@venkatratnam4891 3 года назад
after a long time i have seen your mustache
@prsh1989
@prsh1989 5 лет назад
why we use iterator? I mean if we have for loop, then why iterator? Any real world programming example where this is used?
@sheikwaris
@sheikwaris 4 года назад
have same question
@naveensai4039
@naveensai4039 6 месяцев назад
@prsh1989 for suppose, if u have a string list and then u r trying to check if the list contains one particular value then u need to use iterator to check whether that specific value is present or not. Let us consider another example, suppose u r building a well built structure and if u don't know the length of list or any collections then u need to use next method in iterator and fetch the values if the list contains values in list
@paulhaso
@paulhaso 2 года назад
Excellent video! Thank you
@nilimasharma6849
@nilimasharma6849 2 месяца назад
Instead of raise stop iteration can't we just use a break statement after else
@telugu_rockzz
@telugu_rockzz Месяц назад
No we can't use it
@saicharan4669
@saicharan4669 4 года назад
Sir the video is a little bit confusing regarding creating an our own object of iterator My doubt is initial part of video we created our own iterator object that is it,then what is the difference
@xtonx-theofficialbeechslay1575
@xtonx-theofficialbeechslay1575 2 года назад
i geniunly have a hatred toward people using light mode
@malakhassan9816
@malakhassan9816 5 месяцев назад
How we typed self.num and we hadn't typed method named num or class nemed num?..num is not defined..
@telugu_rockzz
@telugu_rockzz Месяц назад
It is not a parameter it just initialised
@sakthivadivel1057
@sakthivadivel1057 3 года назад
class TopTen: def __init__(self): self.num=1 def __iter__(self): return self def __next__(self): val=self.num self.num += 1 return val values = TopTen() for i in values: print(i) ------------ i'm getting error like: TypeError: 'TopTen' object is not iterable ------------ Could'u help me to fix this ?
@volundthe_smith7623
@volundthe_smith7623 Год назад
Good
@somethingnew6966
@somethingnew6966 Год назад
Where are you from?
@divyanshijaiswal8500
@divyanshijaiswal8500 4 года назад
Sir, please make on video of game development and app development.
@yamini_ramesh7433
@yamini_ramesh7433 4 года назад
Object is not iterable sir what's the prblm
@avert_
@avert_ 5 лет назад
what is the use of __init__(self)? why cant we simply use val and increment values to it?
@telugutravellerraj
@telugutravellerraj 5 лет назад
__init__ is to initialize the variable, here 'num'.
@veeramallabhoomika3435
@veeramallabhoomika3435 4 года назад
Sir, At last when we call print values then we should two ones because of init function and other one is because of iter function but we are getting only one value of 1. I am not understanding this can you help me in this.
@TheProgrammingJourney
@TheProgrammingJourney 3 года назад
This is because the iter is storing the value of self and that is none other but 1 in beginning but when the next()is called the value of the value of the self.num became 2 which would be passed as self in iter next time (in the for loop)
@p.l.ramakrishna4015
@p.l.ramakrishna4015 2 года назад
we are hearing to learn, not checking your talent.
@ankuragarwal4014
@ankuragarwal4014 4 года назад
sir how to do text parsing in python?
@himanshumangal483
@himanshumangal483 4 года назад
Nice!
@sohailanwar7536
@sohailanwar7536 3 года назад
In pycharm you can use (control + d) to copy the line and paste it onto the next in the place of using (ctrl + c) and (ctrl + v).
@mehulsharma7333
@mehulsharma7333 2 года назад
Thanks 👍
@gokulkrishnayt
@gokulkrishnayt 2 года назад
Thanks Buddy😊
@atlasatlantis8447
@atlasatlantis8447 Год назад
I'm pretty sure it's the same for all windows programs. You can even copy youtube comments this way.
@AshiqAli-ie5pm
@AshiqAli-ie5pm Год назад
Thanks bro
@adilbougma2706
@adilbougma2706 4 года назад
omg you are a true programmer :D i lauoh so hard when the output print None. i like you debuging method
@ajaybhandari9215
@ajaybhandari9215 4 года назад
at which point in the video?
@Someone-kw6mw
@Someone-kw6mw 4 года назад
binod bonod
@HackingWithCoffee
@HackingWithCoffee 5 лет назад
Sir can you please create video on data structure and algorithm
@harshavardhan.g351
@harshavardhan.g351 4 года назад
watch jenny lectures for ds and algo
@bhaveshjhawar9532
@bhaveshjhawar9532 3 года назад
watch code with harry .. thank me later
@schruteman7444
@schruteman7444 2 года назад
@@bhaveshjhawar9532 thank u
@harshamin7996
@harshamin7996 2 года назад
Sir, Why can't we use break in else part to stop the execution of for loop ?
@realsumitkumar
@realsumitkumar 2 года назад
Break is used only inside a loop
@utpalpodder-pk6vq
@utpalpodder-pk6vq 4 года назад
whether during the creation of the object itself __iter__() method is called just like __init__() method? Is __iter__() method is called only once?
@pinakibhattacharya2761
@pinakibhattacharya2761 4 года назад
and instead of giving exception in else part can we give break statement at the end of if statement?
@rajeshwardutta
@rajeshwardutta 4 года назад
I don't think you could. Break works for loops, but IF is a conditional operator.
@puneet8705
@puneet8705 4 года назад
not break but breakpoint will work
@addagallanaresh4044
@addagallanaresh4044 3 года назад
@@rajeshwardutta switch is also conditional entry but it supports break..its not a loop
@komaljoshi2272
@komaljoshi2272 5 лет назад
hi sir,I don't have IT background ,completed B.Sc. Zoology in 2013, now keen to join IT field,so can I start my career in Python ? Are jobs available for fresher Python Developer in market? Could you please guide?
@anujdahiya341
@anujdahiya341 5 лет назад
i'm in somewhat same situation
@OasisFinder
@OasisFinder 3 года назад
Python is booming in terms of job in 2020. even if you are not from IT learn this , take your time and you can
@divyanshusingh6105
@divyanshusingh6105 4 года назад
I really Want to thank you Navin Sir..My college faculty never focus on the concepts of programming they are just making us rattutota... Thank you so much sir for coming on youtube and helping the students
@balla4004
@balla4004 4 года назад
What is meant by rattutato
@rayyanamir8560
@rayyanamir8560 3 года назад
@@balla4004 He means rattu tota.
@amalayakin4411
@amalayakin4411 2 года назад
Our college also the same scenarios happens
@vishutanwar
@vishutanwar 2 года назад
@@balla4004 means they just make student memorise programing
@sivasaran4
@sivasaran4 3 года назад
can we use break instead of "raise stop iteration"
@virtualmagic5489
@virtualmagic5489 3 года назад
same doubt
@karthikreddy4430
@karthikreddy4430 3 года назад
@@virtualmagic5489 break can only be used in for loop and switch i guess
@pradeepmedikonda7282
@pradeepmedikonda7282 5 лет назад
What is the use of iterator while we have a for loop and we can go for a every element of the list....
@adnanfaisal1085
@adnanfaisal1085 4 года назад
same queston
@moisesdiaz9852
@moisesdiaz9852 4 года назад
same question here too
@moisesdiaz9852
@moisesdiaz9852 4 года назад
I just found it, its because iterators use much less resources than the traditional loop
@sanjaykrish8719
@sanjaykrish8719 4 года назад
internally the list is an iterator that has next and iter methods implemented and that's why you could use the for loop in list. What Navin teaches is you could create your own custom iterator
@bmanicharanreddy7386
@bmanicharanreddy7386 4 года назад
actually for loop made up of iterator object
@shrihari8886
@shrihari8886 4 года назад
hiii bro, create the own class that not repeat again values...but inbuild the value or nums it can repeating ....i wanna clear about it this video
@akashgandhi7886
@akashgandhi7886 4 года назад
first example in list: values are repeated but while creating our own iterator values not repeated why this is happen plzz give me the difference of this scenario
@HassanRahamathullah
@HassanRahamathullah 3 года назад
In first example with list, if you observe carefully, he is performing for loop on the list object not on the iterator (it). If you perform for loop on "it" it would continue from where you left using "it.__next__()" function.
@Engineerincubicle
@Engineerincubicle 5 лет назад
Sir, My Final Year Project is on Virtual Mouse using Hand gestures using OpenCV and Python,Can you please help me in this,Sir?
@merowe123
@merowe123 4 года назад
Nothing is free
@ryouko2971
@ryouko2971 5 лет назад
Under the def __iter__() method, why are we returning self only? And what does he mean by 'returning the object' when using this method? It's just a self keyword with no parameters. What does this mean? Please help
@guru_bro
@guru_bro 3 года назад
Bro do u got ur answer please explain me. I'm stuck for days
@sagarr1640
@sagarr1640 3 года назад
By this way are v overloading the Iter & next inbuilt function ?
@siddharthmishra8233
@siddharthmishra8233 2 года назад
yes sort of.
@shaiksubhan2306
@shaiksubhan2306 5 лет назад
What is going on behind for loop it is good,,,, but what is the use of iterator
@banti000
@banti000 5 лет назад
Iter is linked to next , how and what it's doing,(return self) !
@harshavardhandsh5190
@harshavardhandsh5190 5 лет назад
I could not understand the benefits of iterator over cute for loop
@aldrinsaurovsarker5159
@aldrinsaurovsarker5159 4 года назад
@@harshavardhandsh5190 used in data structures
@naesone2653
@naesone2653 3 года назад
wow you really explain well and are one of the few indians that have no accent almost respect
@zeeshanshahidansari9425
@zeeshanshahidansari9425 4 года назад
Nice mustache! It suits you Sir. :-)
@zakiasmaa6834
@zakiasmaa6834 Месяц назад
I really want to Thank you Sir for all the efforts and also for your nice energy, I hope that you still have this awsome energy and vibes, God bless you !!!
@mrvilgax1183
@mrvilgax1183 Год назад
how many of you went back video and see he have mustache(search meaning in google) of our teacher 😂🤣🤣
@ursABD
@ursABD Год назад
In if condition can we use break to stop the iteration 9:33
@dobbysurfs
@dobbysurfs Год назад
Im sorry to say your explanation is becoming staler and actually complicates the concepts,for the last 3 videos including this one .i had to go to another video and learn it and comeback here.i hope i don't have to do that every video from now on
@keerthichowdary750
@keerthichowdary750 4 года назад
sir!!!! in the before example u have shown the repeation of values getting in output...but in this example why it is not repaeting 1 and taking next values......
@dhamoramesh8210
@dhamoramesh8210 3 года назад
have you cleared that doubt ? if yes please explain
@haaahaaa8396
@haaahaaa8396 4 года назад
Sir, where have you learnt all this stuff . I am watching the whole series,your concepts are strong. Can you please tell me which course or way should I choose , For web development via. Python. I am cs student. 2nd yr
@mohammadmohsinmohammedmohs9717
@mohammadmohsinmohammedmohs9717 4 года назад
Even I am second year student, can you tell whether you are understanding oops concepts?? I'm not able to get it
@hxrsh_x
@hxrsh_x 3 года назад
@@mohammadmohsinmohammedmohs9717 seach for "Corey Schafer OOPs tutorial in Python"
@OasisFinder
@OasisFinder 3 года назад
The way sir explain things is clear that its his past over all experience and strong understanding of OOPs, The reason i said this because every developer has its own way to clear concepts, Maybe you clear your concepts by watching or reading other videos or book.
@amritanshusinghbhumihar
@amritanshusinghbhumihar 2 года назад
Experience.
@30.ayushyadav41
@30.ayushyadav41 Месяц назад
instead of for why we don't use while i
@pothalasiva4820
@pothalasiva4820 4 года назад
Sir why can't we use break statement 🤔🤔
@prakharprakashverma2409
@prakharprakashverma2409 4 года назад
bcoz break keyword is used to break loops but here if condition is used
@cinemaplus150
@cinemaplus150 4 года назад
Sir can u make video for machine learning usking sklearn lib for data science
@siddharthrautara8811
@siddharthrautara8811 4 года назад
sir can you let us know a real life example where we use iterator
@chandrasekar3653
@chandrasekar3653 5 лет назад
I just debug and found how that statement for i in values just calls the next function in Topten class , every time after printing the value of i . This is awesome . You should include a debug session in this video itself.
@nithinsamudrala9697
@nithinsamudrala9697 4 года назад
Chandra Sekar how can for loop call next method?
@arifurbhuyan8372
@arifurbhuyan8372 9 месяцев назад
not sure why this particular lecture was needed :( .. was very confusing
@RamKaruna-em3xh
@RamKaruna-em3xh 5 месяцев назад
Sir other way to stop the loop is self.num=self.num+0 , is this right sir
@tanaysamanta4730
@tanaysamanta4730 3 года назад
def __iter__(self): return self What is the reason of using it? Can anyone explain?
@prachinainawa3055
@prachinainawa3055 5 лет назад
It will be very very gladful if you give sometime in answering the good questions asked by us. Because we get into some confusion whose answers are not available on google. Then we got stucked there. So please at least give us any opportunity to get the confusion clear in between 2 days so that we will also don't lose the interest in clearing the questions. If you don't have that much time then you can also answer only necessary and tough questions.
@OasisFinder
@OasisFinder 3 года назад
agree.. but thing is not everyone read comments or those who read dont go deep down in comment section, Just like i replied your comment after one year lol
@guru_bro
@guru_bro 3 года назад
Can u help for one doubt please I'm stuck for days
@OasisFinder
@OasisFinder 3 года назад
@@guru_bro Where?
@guru_bro
@guru_bro 3 года назад
@@OasisFinder what does iter Dunder method do and y it returns self what is the use of returning same object which is passed?
@shivangigoel9170
@shivangigoel9170 5 лет назад
class TOPT: def __int__(self): self.num=1 def __iter__(self): return self def __next__(self): if self.num
@shivangigoel9170
@shivangigoel9170 5 лет назад
@Leonardo cool thanks
@chandusree3248
@chandusree3248 5 лет назад
That is --init-- not --int--
@subasrim962
@subasrim962 4 года назад
Your mistakes for loop...for I in values Print (i)
@vikaspal2799
@vikaspal2799 3 года назад
Why do we need the iter() method while defining our own iterator???
@user-rn6zc7vp3h
@user-rn6zc7vp3h 3 года назад
Yeah no need of iter if our class have next method and we are not even calling iter
@dobbysurfs
@dobbysurfs Год назад
You are making your object an iterator ,next method can only be used if there is an iterator.
@yashsalvi6850
@yashsalvi6850 4 года назад
Can someone help me know that what happens after "for i in values " is called ?
@ContentArm
@ContentArm 4 года назад
__iter__() is called and then __iter__() calls __next__(). __next__() runs till the exception is raised.
@guru_bro
@guru_bro 3 года назад
@@ContentArm can u elaborate on this please maybe on insta
@farazahmed1668
@farazahmed1668 5 лет назад
Hello sir, love from Pakistan...!
@sepehrtavakoli591
@sepehrtavakoli591 11 месяцев назад
It prints 1to10 but if we remove for loop it will give you only one
@mayankrajput2889
@mayankrajput2889 2 месяца назад
Can we say we are using method overloading here?
@onnlyfutebol
@onnlyfutebol 3 года назад
I still can't seem to comprehend the word iterate, aswell when he says it 'loops' over. I would really appreciate if anyone could dumb down the explanation as much as possible I'm desperate to understand this concept lol. Thank you in advance
@KoreanPanda
@KoreanPanda 3 года назад
I'm confused. Couldn't we just print "nums" to output the values? Why did we need a "for" statement to display all 4 values?
@sowmya6005
@sowmya6005 3 года назад
why even without calling iter and next methods they are running
@vanshikasharma481
@vanshikasharma481 3 года назад
hiii bro, create the own class that not repeat again values...but inbuild the value or nums it can repeating ....i wanna clear about it this video
@vanshikasharma481
@vanshikasharma481 3 года назад
help me with this pls
@iamniks
@iamniks 4 года назад
sir i have a question Why u used " raise StopIteration " ? why not u use " Break " instead ??? please explain anyone
@OasisFinder
@OasisFinder 3 года назад
break works on LOOPs "for" or "while" not conditions like "if"
@hassnainamjad1059
@hassnainamjad1059 3 года назад
modified iterators form where to start and where to stop: class ur_choice: def __init__(self, num): self.nums = int(input('enter from where to start')) def __iter__(self): return self def __next__(self): if self.nums
@narragopichand9982
@narragopichand9982 3 года назад
If something is returned in a function it return value to function call right ? What is happening to return here. Object is being returned......
@bharathkumar5870
@bharathkumar5870 4 года назад
list is already an iterator.why making it iterator again
@ITSkillswithSurajDatir
@ITSkillswithSurajDatir 3 года назад
looking handsome
@rajkumar-nx1me
@rajkumar-nx1me 5 лет назад
sir what is the advantage of iterator over for loop
@ankitchetri2968
@ankitchetri2968 3 года назад
To be honest i understood this better from u sir in comparison to code with harry ,i m not comparing but actually u r a little better in explaining , don't kill me code with harry fans i am also his fan it's just my opinion
@tanmayisharma5890
@tanmayisharma5890 Год назад
What happens if we print(next(it)) beyond the range of list? I mean what if we use print statement 6 time if the list has only 5 values? And can we access the index of an element using iter() and next()?
@mounikak3818
@mounikak3818 4 года назад
what is the use i dint understand when u want to print one by one it is done in 1st example bt in 2ns e ample own iterator all numbers are printed at once not as u told one by one dint understand what’s the real use u want to tell sir
@ElyasSAhmad
@ElyasSAhmad 4 года назад
class iterator: def __init__(self): self.a = 0 def __iter__(self): return self def __str__(self): return '{}'.format(self.a) def __next__(self): if self.a
@dragonwarrior7442
@dragonwarrior7442 5 лет назад
class Habit(Str): pass print(Habit("yellow")) O/p :. Yellow How it works internal Plzzz sir it's important for me
@placement3608
@placement3608 5 лет назад
It's so simple bro
@placement3608
@placement3608 5 лет назад
Pass used so it will skip that part
@telugutravellerraj
@telugutravellerraj 5 лет назад
It gives error "NameError: name 'Str' is not defined". How did you get output 'Yellow' ?
@paristar3079
@paristar3079 4 года назад
@@telugutravellerraj You first have to define a class named Str and define init method which takes in a string ... Remember the case sensitivity And it still won't output yellow ... It will print the object itself
@pramitharyan5167
@pramitharyan5167 4 года назад
one more video on iterator please
@Shubhamfoodshorts
@Shubhamfoodshorts 3 года назад
since we already have for loop to iterate the list then why are we making things more complex by making this iterator
@mohamednayeem2602
@mohamednayeem2602 6 месяцев назад
this we can use for interview question but for loop is the best. I haven't used this loop in my entire life
@virtualmagic5489
@virtualmagic5489 3 года назад
What does that __iter__() method do here sir
@Abhishekkumarsingh-sl5yz
@Abhishekkumarsingh-sl5yz 5 лет назад
sir after class python is becoming difficult any suggestion
@Bhabani1994
@Bhabani1994 5 лет назад
concept is extremely good no doubt on that, but your new look does not matching with personality..... but really your teaching style is awesome, thank god that you are providing such valuable knowledge with free of cost...
@desiandhomemade
@desiandhomemade 4 года назад
it should not print the value "1" again because now value pointer has moved to next which is "2"
@AbdulKalamchessebank
@AbdulKalamchessebank 4 года назад
Complex program...😥
@rakeshmali1727
@rakeshmali1727 8 месяцев назад
at 5:11, why did the for loop print 7 and 8 again? this contradicts with 10:22 no?
@Rajadahana
@Rajadahana 2 года назад
If you type print(next(values)) after the for loop, you will get an Error.
@pratimamaurya8890
@pratimamaurya8890 3 года назад
please make series on python turtle
@bantigarg740
@bantigarg740 4 года назад
Hey if we have for loop to print 1 to 10 number, why should we use this iterator
@muzikizmylyf8411
@muzikizmylyf8411 5 лет назад
I like your learning style
@ahababbinhabibosama2565
@ahababbinhabibosama2565 2 года назад
I like your moustache
@srushtiagarwal2748
@srushtiagarwal2748 5 лет назад
very interesting and knowledgeable tutorial.👌👍
@KeremAli-cm3pj
@KeremAli-cm3pj 2 месяца назад
Also very interesting mustache (❁´◡`❁)(●'◡'●)
@dhruvchaudhary8054
@dhruvchaudhary8054 3 года назад
sir could you please suggest me a source from where i can practice python, please!!
Далее
#62 Python Tutorial for Beginners | Generators
6:11
Просмотров 312 тыс.
Abstract Class and Abstract Method in Python
12:29
Просмотров 362 тыс.
КОТЯТА В ОПАСНОСТИ?#cat
00:36
Просмотров 1,1 млн
Barno
00:22
Просмотров 708 тыс.
#64 Python Tutorial for Beginners | MultiThreading
14:45
Iterators vs. Generators in Python : Data Science Code
12:37
10 Python Comprehensions You SHOULD Be Using
21:35
Просмотров 148 тыс.
#63 Python Tutorial for Beginners | Exception Handling
15:59
Python Generators Explained
28:37
Просмотров 155 тыс.