#61 Python Tutorial for Beginners | Iterator

Поділитися
Вставка

КОМЕНТАРІ • 278

  • @sohailanwar7536
    @sohailanwar7536 3 роки тому +68

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

  • @jimmymesa
    @jimmymesa 5 років тому +13

    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.

  • @divyanshusingh6105
    @divyanshusingh6105 4 роки тому +19

    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 3 роки тому +1

      What is meant by rattutato

    • @rayyanamir8560
      @rayyanamir8560 2 роки тому

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

  • @swethasundaram04
    @swethasundaram04 3 роки тому +14

    The raise keyword is used to raise an exception. You can define what kind of error to raise(here its StopIteration).

    • @shivasaiprasadakula7386
      @shivasaiprasadakula7386 2 роки тому +1

      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 років тому +21

    Sir, when will you make videos on tikinter and other python GUI?

  • @chandrasekar3653
    @chandrasekar3653 4 роки тому +6

    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.

  • @sriram9786
    @sriram9786 4 роки тому +19

    sir can you put another vedio on this. i dint understand completely.

  • @srushtiagarwal2748
    @srushtiagarwal2748 4 роки тому +7

    very interesting and knowledgeable tutorial.👌👍

  • @adilbougma2706
    @adilbougma2706 4 роки тому +14

    omg you are a true programmer :D i lauoh so hard when the output print None. i like you debuging method

  • @anonymous_anonymity
    @anonymous_anonymity 5 років тому +2

    Excellent tutorial 👍👍

  • @muzikizmylyf8411
    @muzikizmylyf8411 4 роки тому +1

    I like your learning style

  • @paulhaso
    @paulhaso Рік тому

    Excellent video! Thank you

  • @mohamednayeem2602
    @mohamednayeem2602 4 місяці тому

    this we can use for interview question but for loop is the best. I haven't used this loop in my entire life

  • @BryceDoesLife
    @BryceDoesLife 4 роки тому +14

    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?

  • @user-pm3ou4dm4w
    @user-pm3ou4dm4w 3 роки тому

    Thank you Mr. Navin !

  • @anuragrsimha
    @anuragrsimha 4 роки тому +1

    ಸರ್...ನಿಮ್ಮ teaching ನನಗೆ ಬಹಳ ಇಷ್ಟ. ಈ videoಇಂದ ನನ್ನ ಎಲ್ಲಾ doubtಗಳು clear ಆದವು. ಧನ್ಯವಾದಗಳು.
    సర్...మీరు teaching నాకు చాలా ఇష్టం. ఈ video నుండి నా అన్ని doubtలు clear ఆయింది. ధన్యవాదలు.
    ಜೈ ಕರ್ನಾಟಕ (జై కర్నాటక)!!
    ಜೈ ಕನ್ನಡ (జై కన్నడ)!!

    • @nuqlear1189
      @nuqlear1189 Місяць тому

      kannada pig idli sambhar

  • @zeeshanshahidansari9425
    @zeeshanshahidansari9425 3 роки тому +3

    Nice mustache! It suits you Sir. :-)

  • @Bhabani1994
    @Bhabani1994 4 роки тому

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

  • @startjourney8631
    @startjourney8631 3 роки тому +1

    Dil se dhanywaad🙏✌️🤗

  • @jaikishankumarmore1457
    @jaikishankumarmore1457 4 роки тому

    Brilliant, thanks a lot!

  • @naesone2653
    @naesone2653 3 роки тому +5

    wow you really explain well and are one of the few indians that have no accent almost respect

  • @pawnage3
    @pawnage3 2 роки тому

    Thank you Mr. Reddy!

  • @utpalpodder-pk6vq
    @utpalpodder-pk6vq 4 роки тому +4

    whether during the creation of the object itself __iter__() method is called just like __init__() method?
    Is __iter__() method is called only once?

  • @anoshkaniskar1482
    @anoshkaniskar1482 3 роки тому

    The when you say Iterators. How cool is that..

  • @HackingWithCoffee
    @HackingWithCoffee 5 років тому +64

    Sir can you please create video on data structure and algorithm

  • @venkatratnam4891
    @venkatratnam4891 3 роки тому

    after a long time i have seen your mustache

  • @mahdi-hasan
    @mahdi-hasan Рік тому

    If you want to work the loop for multiple times put "self.num = 1" in else condition.

  • @naingmind5709
    @naingmind5709 2 роки тому

    Finally I got this yayyyyy

  • @harshamin7996
    @harshamin7996 2 роки тому +8

    Sir,
    Why can't we use break in else part to stop the execution of for loop ?

  • @naufilibrahimmukadam7023
    @naufilibrahimmukadam7023 5 років тому +1

    Sir, Pune MeetUp when....???

  • @shaiksubhan2306
    @shaiksubhan2306 4 роки тому +2

    What is going on behind for loop it is good,,,, but what is the use of iterator

  • @ahmetsarkaya9203
    @ahmetsarkaya9203 4 роки тому

    "try and except" also could be used right? Was there any reason that stopped you to use "try and except" ?

  • @Maks05N
    @Maks05N 3 роки тому

    It's very funny when you said to NONE iteration "eehh HOLD on"

  • @pratikgon522
    @pratikgon522 4 роки тому

    if I use exit() instead of Raise Iteration then what problem would I face?

  • @pramitharyan5167
    @pramitharyan5167 4 роки тому +1

    one more video on iterator please

  • @siddharthrautara8811
    @siddharthrautara8811 4 роки тому +2

    sir can you let us know a real life example where we use iterator

  • @054_ritesh3
    @054_ritesh3 3 роки тому

    Good sir ji👍👍👍

  • @rajkumar-nx1me
    @rajkumar-nx1me 4 роки тому +1

    sir what is the advantage of iterator over for loop

  • @dnyaneshwarkadam6823
    @dnyaneshwarkadam6823 5 років тому

    Thanks 😊....

  • @palanitpt
    @palanitpt 5 років тому

    Thank you

  • @tanmayisharma5890
    @tanmayisharma5890 9 місяців тому

    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()?

  • @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?

  • @cinemaplus150
    @cinemaplus150 4 роки тому +1

    Sir can u make video for machine learning usking sklearn lib for data science

  • @Abhishekkumarsingh-sl5yz
    @Abhishekkumarsingh-sl5yz 5 років тому +1

    sir after class python is becoming difficult any suggestion

  • @Rajadahana
    @Rajadahana 2 роки тому

    If you type
    print(next(values))
    after the for loop, you will get an Error.

  • @omkarmore7017
    @omkarmore7017 4 роки тому +1

    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

  • @bantigarg740
    @bantigarg740 3 роки тому

    Hey if we have for loop to print 1 to 10 number, why should we use this iterator

  • @ursABD
    @ursABD 10 місяців тому +1

    In if condition can we use break to stop the iteration 9:33

  • @PawanKumar-cm6lg
    @PawanKumar-cm6lg 3 роки тому +2

    '1' will be printed twice as the 'for loop' always starts from the 1st element in the list. so both are different things and it will give the twice ones then will continue up to what we want to print.

  • @divyanshijaiswal8500
    @divyanshijaiswal8500 4 роки тому

    Sir, please make on video of game development and app development.

  • @prachinainawa3055
    @prachinainawa3055 4 роки тому +2

    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.

    • @zuberkhan-kn7iu
      @zuberkhan-kn7iu 3 роки тому +1

      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

    • @zuberkhan-kn7iu
      @zuberkhan-kn7iu 3 роки тому

      @@guru_bro Where?

    • @guru_bro
      @guru_bro 3 роки тому

      @@zuberkhan-kn7iu what does iter Dunder method do and y it returns self what is the use of returning same object which is passed?

  • @abhishekroushan9735
    @abhishekroushan9735 3 роки тому

    is there any way of using variable in place of self.num = 1 means self.num = n and then iterate it for 10 times

  • @shrihari8886
    @shrihari8886 3 роки тому +1

    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

  • @sheikwaris
    @sheikwaris 4 роки тому

    Navin, pls stat what is the purpose of __iter__ method at all

  • @pinakibhattacharya2761
    @pinakibhattacharya2761 4 роки тому +9

    and instead of giving exception in else part can we give break statement at the end of if statement?

    • @rajeshwardutta
      @rajeshwardutta 4 роки тому +2

      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

  • @ryouko2971
    @ryouko2971 5 років тому +1

    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 роки тому +1

      Bro do u got ur answer please explain me. I'm stuck for days

  • @himanshumangal483
    @himanshumangal483 4 роки тому

    Nice!

  • @pratimamaurya8890
    @pratimamaurya8890 3 роки тому

    please make series on python turtle

  • @shubhamvashisth2886
    @shubhamvashisth2886 3 роки тому

    since we already have for loop to iterate the list then why are we making things more complex by making this iterator

  • @narragopichand9982
    @narragopichand9982 2 роки тому

    If something is returned in a function it return value to function call right ? What is happening to return here. Object is being returned......

  • @rakeshmali1727
    @rakeshmali1727 5 місяців тому

    at 5:11, why did the for loop print 7 and 8 again? this contradicts with 10:22 no?

  • @alaapsarkar
    @alaapsarkar 3 роки тому

    print statement prints 1 and the for loop prints 2, 3, 4,..., 10

  • @hamzabohra3267
    @hamzabohra3267 3 роки тому

    sir why are we using raise ? can we not use break

  • @msarkar9779
    @msarkar9779 3 роки тому

    what is the use of- values=toptens ?

  • @LoveToLearnExplore
    @LoveToLearnExplore Рік тому

    nice video

  • @kamalpathak4065
    @kamalpathak4065 3 роки тому

    So why we use loop if we have iterators

  • @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

  • @santhoshbyri125
    @santhoshbyri125 4 роки тому +1

    break also possible

  • @harshgupta9761
    @harshgupta9761 4 роки тому

    Why only return self is use under iter block

  • @utkarshsoni7938
    @utkarshsoni7938 5 років тому +1

    First view!
    For the first time.

  • @malakhassan9816
    @malakhassan9816 2 місяці тому

    How we typed self.num and we hadn't typed method named num or class nemed num?..num is not defined..

  • @EruditeGaming
    @EruditeGaming 4 роки тому

    Sir, can we use limiter in __next__

  • @srilakshmi4620
    @srilakshmi4620 4 роки тому

    how to goto previous element in interator?

  • @volundthe_smith7623
    @volundthe_smith7623 Рік тому

    Good

  • @sepehrtavakoli591
    @sepehrtavakoli591 8 місяців тому

    It prints 1to10 but if we remove for loop it will give you only one

  • @Engineerincubicle
    @Engineerincubicle 5 років тому +8

    Sir, My Final Year Project is on Virtual Mouse using Hand gestures using OpenCV and Python,Can you please help me in this,Sir?

  • @nehaaadarsh
    @nehaaadarsh 4 роки тому

    Sir what if want user input??

  • @sowmya6005
    @sowmya6005 3 роки тому

    why even without calling iter and next methods they are running

  • @dhruvchaudhary8054
    @dhruvchaudhary8054 2 роки тому

    sir could you please suggest me a source from where i can practice python, please!!

  • @sagarr1640
    @sagarr1640 2 роки тому +1

    By this way are v overloading the Iter & next inbuilt function ?

  • @keerthichowdary750
    @keerthichowdary750 3 роки тому +1

    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

  • @virtualmagic5489
    @virtualmagic5489 3 роки тому

    What does that __iter__() method do here sir

  • @nilimasharma6849
    @nilimasharma6849 4 години тому

    Instead of raise stop iteration can't we just use a break statement after else

  • @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

  • @prashantkumargautam4191
    @prashantkumargautam4191 3 роки тому

    It will print 1 or 11?

  • @pradeepmedikonda7282
    @pradeepmedikonda7282 5 років тому +31

    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 роки тому +3

      same queston

    • @moisesdiaz9852
      @moisesdiaz9852 4 роки тому

      same question here too

    • @moisesdiaz9852
      @moisesdiaz9852 4 роки тому +5

      I just found it, its because iterators use much less resources than the traditional loop

    • @sanjaykrish8719
      @sanjaykrish8719 4 роки тому +8

      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 роки тому +2

      actually for loop made up of iterator object

  • @khasimvali3303
    @khasimvali3303 4 роки тому

    Can we use break instead of raising exception?

  • @ankuragarwal4014
    @ankuragarwal4014 4 роки тому

    sir how to do text parsing in python?

  • @mohammadziauddin6270
    @mohammadziauddin6270 Рік тому

    There was an indentation error at return val thats why its repeating., remove 1 space before return.

  • @avert_
    @avert_ 4 роки тому

    what is the use of __init__(self)? why cant we simply use val and increment values to it?

  • @sivasaran4
    @sivasaran4 3 роки тому +2

    can we use break instead of "raise stop iteration"

  • @arkeys8764
    @arkeys8764 4 роки тому

    Where are we calling next function in for loop and without calling it how the value are printing??

    • @GS7999
      @GS7999 3 роки тому

      for loop is executed for every value (i.e i) in "values" and "values" is calling class Topten().
      All the methods inside Topten() will be executed everytime "values" calls the class Topten()

  • @desiandhomemade
    @desiandhomemade 4 роки тому

    it should not print the value "1" again because now value pointer has moved to next which is "2"

  • @saitangudu3650
    @saitangudu3650 4 роки тому

    Can u please tell the time complexity for the iterators

  • @farazahmed1668
    @farazahmed1668 5 років тому +5

    Hello sir, love from Pakistan...!

  • @haaahaaa8396
    @haaahaaa8396 4 роки тому +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"

    • @zuberkhan-kn7iu
      @zuberkhan-kn7iu 3 роки тому +1

      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.

  • @RamKaruna-em3xh
    @RamKaruna-em3xh 3 місяці тому

    Sir other way to stop the loop is self.num=self.num+0 , is this right sir

  • @saitanush9453
    @saitanush9453 3 роки тому

    tq

  • @nikhilgaikwad5159
    @nikhilgaikwad5159 5 років тому

    PCAP Certification?

  • @mounikak3818
    @mounikak3818 3 роки тому

    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