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
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... 👍🥰
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.
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 !!!
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
ಸರ್...ನಿಮ್ಮ teaching ನನಗೆ ಬಹಳ ಇಷ್ಟ. ಈ videoಇಂದ ನನ್ನ ಎಲ್ಲಾ doubtಗಳು clear ಆದವು. ಧನ್ಯವಾದಗಳು. సర్...మీరు teaching నాకు చాలా ఇష్టం. ఈ video నుండి నా అన్ని doubtలు clear ఆయింది. ధన్యవాదలు. ಜೈ ಕರ್ನಾಟಕ (జై కర్నాటక)!! ಜೈ ಕನ್ನಡ (జై కన్నడ)!!
@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
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
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
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
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.
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.
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
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...
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?
'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.
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
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.
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......
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()?
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 ?
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
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
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
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.
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)
What is the significance of returning the object itself? I cannot understand why we cannot use the "values" object itself for the iteration. Please help.
__init__ is a special method in Python classes, it is the constructor method for a class. It is called when ever an object of the class is constructed.
The logic for inbuilt "for loop " is itself iterator concept only.but if you want to use "for loop" for your own created objects you have to define a iterator
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()
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).
Thanks 👍
Thanks Buddy😊
I'm pretty sure it's the same for all windows programs. You can even copy youtube comments this way.
Thanks bro
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
What is meant by rattutato
@@balla4004 He means rattu tota.
Our college also the same scenarios happens
@@balla4004 means they just make student memorise programing
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.
The raise keyword is used to raise an exception. You can define what kind of error to raise(here its StopIteration).
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... 👍🥰
sir can you put another vedio on this. i dint understand completely.
omg you are a true programmer :D i lauoh so hard when the output print None. i like you debuging method
at which point in the video?
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.
Chandra Sekar how can for loop call next method?
Sir, when will you make videos on tikinter and other python GUI?
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 !!!
wow you really explain well and are one of the few indians that have no accent almost respect
Sir can you please create video on data structure and algorithm
watch jenny lectures for ds and algo
watch code with harry .. thank me later
@@bhaveshjhawar9532 thank u
Sir,
Why can't we use break in else part to stop the execution of for loop ?
Break is used only inside a loop
whether during the creation of the object itself __iter__() method is called just like __init__() method?
Is __iter__() method is called only once?
What is the use of iterator while we have a for loop and we can go for a every element of the list....
same queston
same question here too
I just found it, its because iterators use much less resources than the traditional loop
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
actually for loop made up of iterator object
and instead of giving exception in else part can we give break statement at the end of if statement?
I don't think you could. Break works for loops, but IF is a conditional operator.
not break
but breakpoint will work
@@rajeshwardutta switch is also conditional entry but it supports break..its not a loop
ಸರ್...ನಿಮ್ಮ teaching ನನಗೆ ಬಹಳ ಇಷ್ಟ. ಈ videoಇಂದ ನನ್ನ ಎಲ್ಲಾ doubtಗಳು clear ಆದವು. ಧನ್ಯವಾದಗಳು.
సర్...మీరు teaching నాకు చాలా ఇష్టం. ఈ video నుండి నా అన్ని doubtలు clear ఆయింది. ధన్యవాదలు.
ಜೈ ಕರ್ನಾಟಕ (జై కర్నాటక)!!
ಜೈ ಕನ್ನಡ (జై కన్నడ)!!
kannada pig idli sambhar
this we can use for interview question but for loop is the best. I haven't used this loop in my entire life
why we use iterator? I mean if we have for loop, then why iterator? Any real world programming example where this is used?
have same question
@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
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
Bro do u got ur answer please explain me. I'm stuck for days
can we use break instead of "raise stop iteration"
same doubt
@@virtualmagic5489 break can only be used in for loop and switch i guess
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
What is going on behind for loop it is good,,,, but what is the use of iterator
In if condition can we use break to stop the iteration 9:33
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?
This was exactly what I needed thank you
seems like you are an music artist, do u use python in music some way?
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
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
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.
Nice mustache! It suits you Sir. :-)
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.
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
Can u help for one doubt please I'm stuck for days
@@guru_bro Where?
@@OasisFinder what does iter Dunder method do and y it returns self what is the use of returning same object which is passed?
By this way are v overloading the Iter & next inbuilt function ?
yes sort of.
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...
instead of for why we don't use
while i
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?
i'm in somewhat same situation
Python is booming in terms of job in 2020.
even if you are not from IT learn this , take your time and you can
'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.
nope
If something is returned in a function it return value to function call right ? What is happening to return here. Object is being returned......
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
Even I am second year student, can you tell whether you are understanding oops concepts?? I'm not able to get it
@@mohammadmohsinmohammedmohs9717 seach for "Corey Schafer OOPs tutorial in Python"
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.
Experience.
Why do we need the iter() method while defining our own iterator???
Yeah no need of iter if our class have next method and we are not even calling iter
You are making your object an iterator ,next method can only be used if there is an iterator.
at 5:11, why did the for loop print 7 and 8 again? this contradicts with 10:22 no?
Can we say we are using method overloading here?
Sir why can't we use break statement 🤔🤔
bcoz break keyword is used to break loops but here if condition is used
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......
have you cleared that doubt ? if yes please explain
Hello sir, love from Pakistan...!
How we typed self.num and we hadn't typed method named num or class nemed num?..num is not defined..
It is not a parameter it just initialised
Hey if we have for loop to print 1 to 10 number, why should we use this iterator
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()?
Sir, My Final Year Project is on Virtual Mouse using Hand gestures using OpenCV and Python,Can you please help me in this,Sir?
Nothing is free
Sir other way to stop the loop is self.num=self.num+0 , is this right sir
class TOPT:
def __int__(self):
self.num=1
def __iter__(self):
return self
def __next__(self):
if self.num
@Leonardo cool thanks
That is --init-- not --int--
Your mistakes for loop...for I in values
Print (i)
The when you say Iterators. How cool is that..
Dil se dhanywaad🙏✌️🤗
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 ?
I like your learning style
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
sir can you let us know a real life example where we use iterator
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
since we already have for loop to iterate the list then why are we making things more complex by making this iterator
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
very interesting and knowledgeable tutorial.👌👍
Also very interesting mustache
(❁´◡`❁)(●'◡'●)
Can someone help me know that what happens after "for i in values " is called ?
__iter__() is called and then __iter__() calls __next__().
__next__() runs till the exception is raised.
@@ContentArm can u elaborate on this please maybe on insta
"try and except" also could be used right? Was there any reason that stopped you to use "try and except" ?
if I use exit() instead of Raise Iteration then what problem would I face?
sir i have a question
Why u used " raise StopIteration " ? why not u use " Break " instead ??? please explain anyone
break works on LOOPs "for" or "while" not conditions like "if"
Sire, in object creation we have created __iter__ function but we didn't called to make that object as iterator. Then how does it work???
Bcoz it is initialised same as __init__
It prints 1to10 but if we remove for loop it will give you only one
why even without calling iter and next methods they are running
sir what is the advantage of iterator over for loop
sir in the above example we are not calling the iter() and next() method even then it executes how?
Iter is linked to next , how and what it's doing,(return self) !
I could not understand the benefits of iterator over cute for loop
@@harshavardhandsh5190 used in data structures
There was an indentation error at return val thats why its repeating., remove 1 space before return.
def __iter__(self):
return self
What is the reason of using it? Can anyone explain?
If you want to work the loop for multiple times put "self.num = 1" in else condition.
is there any way of using variable in place of self.num = 1 means self.num = n and then iterate it for 10 times
Sir can u make video for machine learning usking sklearn lib for data science
What does that __iter__() method do here sir
Instead of raise stop iteration can't we just use a break statement after else
No we can't use it
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.
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)
sir why are we using raise ? can we not use break
Excellent tutorial 👍👍
Why only return self is use under iter block
sir after class python is becoming difficult any suggestion
So why we use loop if we have iterators
break also possible
what is the use of __init__(self)? why cant we simply use val and increment values to it?
__init__ is to initialize the variable, here 'num'.
Excellent video! Thank you
What is the significance of returning the object itself? I cannot understand why we cannot use the "values" object itself for the iteration. Please help.
__init__ is a special method in Python classes, it is the constructor method for a class.
It is called when ever an object of the class is constructed.
@@ravirobust9499 hi bro can u please elaborate a little more on this? I'm stuck on it for days maybe on insta ?
can't we go like that
for i range(1,11)
print(next(value))
The logic for inbuilt "for loop " is itself iterator concept only.but if you want to use "for loop" for your own created objects you have to define a iterator
one more video on iterator please
after a long time i have seen your mustache
Object is not iterable sir what's the prblm
Sir why did you use if statement in next method. Is there any problem ,if we use (if statement) in for loop
Thank you Mr. Reddy!
No need to raise an Exception here, The return statement should belongs to if block. Then it'll be fine 👍
list is already an iterator.why making it iterator again
If you type
print(next(values))
after the for loop, you will get an Error.
Where are we calling next function in for loop and without calling it how the value are printing??
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()
print statement prints 1 and the for loop prints 2, 3, 4,..., 10
please make series on python turtle
sir could you please suggest me a source from where i can practice python, please!!
Finally I got this yayyyyy
what is the use of- values=toptens ?