After listening to your video at 0.75 times and doing back and forth multiple times I finally understood the closure completely. Thanks for the video.👍👍
These videos are AMAZING. I have watched a lot of python content but IMO this is honestly the best. Not brushing over anything - very technical and the animations are top notch. Fantastic work and thank you so much. You should put up a donate link!
a very good video. I would request you to make a whole python playlist for intermediate to advanced level. You have a very unique way to explaining that make it easy to comprehend.
Amazing.. Sreekant, can you please tune voice over a little bit? I am using 0.75 but still sometimes few words are very fast. And more videos please :). Keep up the good work.
awesome explanation❤🔥 thanks a ton for creating such quality content in best way to make difficult topics easy to understand with deepest explanation 💯
This is an amazing video!! Excellent explanation and animations!! I have subscirbed to you!! By the way, which software do you use for these animations?
You can do this: def counter(num): def increment(inc=1): nonlocal num num += inc return num return increment counter10 = counter(10) closureList = [counter10(3) for a in range(0, 5)] print(closureList) to output this: [13, 16, 19, 22, 25] However, if you don't return num in the inner function, the output (and the list) will be: [None, None, None, None, None] because the inner func is returning nothing, i.e, is returning "None" in each iteration
At 3:50 the arrow pointed to 5 directly, but at 6:45 it pointed to a memory address which in turn points at 5. Is this an actually difference or because you didn't want to complicate things and animated the easy way at 3:50? 3:50 example was using start+=step and 6:45 example (cell object) was using start=start+step, is this what is causing the difference? I ran both examples and observed their co_freevars, closure, co_varnames and they look exactly the same. This makes me think the arrow at 3:50 should also be pointing at a memory address like 6:45 and start+=step vs start=start+step has no difference in this lesson. If this is right, why complicate things using 2 different syntax, if wrong, what differences does += vs + cause in terms of closures?
At all times, Python stores pointers to actual objects and Python takes care of automatic dereferencing (explained in another video ruclips.net/video/0Om2gYU6clE/видео.html, also mentioned at 1:33 in the current video). At 6:45, instead of this one hop, there are two hops. Sometimes I just directly show the value because it's easy, requires less space on the screen, and that part is not what I will be explaining at that point in time. With respect to '+=', there is a difference in how augmented arithmetic operators are handled(explained here ruclips.net/video/0Om2gYU6clE/видео.html). But for immutable objects, end result will be same. I just wanted to make it explicit.
@@sreekanthpr @Sreekanth Thanks for your reply, i have watched the other videos too, really grateful that you make such clear animations to help learners. I understand the difference between += and + from that other video, but when it comes to this video, I still wish to reiterate my question. 1. Why is 3:50 1 hop and 6:45 2 hops? 2. Is the difference in 1. caused by writing start+=step vs start=start+step? 3. Is start+=step vs start=start+step used to demonstrate some other closure related concept in this video if it doesn't cause 1.?
Thanks! There is no difference in start+=step vs start=start+step in closure. I just wanted to emphasize the right-hand side is evaluated first and it gets assigned back to the 'start' variable, that's why I chose to write it explicitly. At 3:50 also there are 2 hops (the cell object exists). But the viewer is assumed to be not aware of the existence of cell objects at that point in time. At 06:32 is where I introduce this internal implementation detail.
@@sreekanthpr Hey, I got everything that you said except for the definition of "closure". It's unclear whether "inner" is a closure. If the enclosed function _(enclosed inside another function, in this case, "inner")_ contains free variables, only then it's a closure, right? I think there are some technical details that I am not able to manacle. _PS: This is high-quality, quintessential content. I am looking forward to "Classes and Objects", "Decorators", "Metaclasses", etc. Also, you should start making videos on Data Structures and Algorithms with Python. I was always interested in the implementation details of CPython. May you achieve 10 million subscribers! I wish you the best of luck!_ :-)
@@nirajraut9408 Yes, the "inner" function is a closure if it it references any variable in its nonlocal scope. Those variables are called "free variables". So, closure is "function + free variables" (or "function + environment") Next video might be on Python's import system covering things like module objects. After that I'm thinking of starting series on data structures.
I had to pause it every few seconds. It's just too quick and full of specialized terminology. Using pause by lector would be beneficial as it would give us time to assimilate the knowledge. I liked the drawings though. :)
After listening to your video at 0.75 times and doing back and forth multiple times I finally understood the closure completely.
Thanks for the video.👍👍
Haha same
A weird question pops into my mind, what percentage of Python programmers really know this level of in-depth knowledge in the real world?
These videos are AMAZING. I have watched a lot of python content but IMO this is honestly the best. Not brushing over anything - very technical and the animations are top notch. Fantastic work and thank you so much. You should put up a donate link!
This is high-quality material!!! Keep up the good work! I hope this channel will grow more and can help others.
High quality, Clarified my doubts.
Nice video! Although a little bit too fast. Thanks!
a very good video. I would request you to make a whole python playlist for intermediate to advanced level. You have a very unique way to explaining that make it easy to comprehend.
I like your way of teaching with visuals. Really helpful!!
This is great. Absolutely great.
Amazing.. Sreekant, can you please tune voice over a little bit? I am using 0.75 but still sometimes few words are very fast. And more videos please :). Keep up the good work.
awesome explanation❤🔥 thanks a ton for creating such quality content in best way to make difficult topics easy to understand with deepest explanation 💯
Exceptional!
Great video, deep info. I had to watch at 0.75 speed cuz so deep.
This is an amazing video!! Excellent explanation and animations!! I have subscirbed to you!! By the way, which software do you use for these animations?
I used github.com/3b1b/manim
would love to connect and see more videos !
awsme!! hope u are doing more such videos ..
great explanation good animations, keep on!
This is great, bro. I've followed your channel.
awesome explanation, really helpful. I look forward upcoming video!!!
You can do this:
def counter(num):
def increment(inc=1):
nonlocal num
num += inc
return num
return increment
counter10 = counter(10)
closureList = [counter10(3) for a in range(0, 5)]
print(closureList)
to output this:
[13, 16, 19, 22, 25]
However, if you don't return num in the inner function, the output (and the list) will be:
[None, None, None, None, None]
because the inner func is returning nothing, i.e, is returning "None" in each iteration
good video, the animations are helpful
excellent
Love this :3
4:27 If `counter` no longer exists, why is it mentioned when we inspect the value of `my_inc`?
What are the use cases of closures in python?
It's the base for decorators. For example, you could implement a basic equivalent of '@functools.lru_cache' using a dictionary as the free variable.
@@sreekanthpr a beginner (which I assume OP is based on his question) has no idea what you just said in your example.
5:08 to me, an object is a thing that has methods, like
counter.increment()
To me, it's counter-intuitive to say
my_inc.increment()
Amazing stuff!!!
best explaination
Can u make a video bout python's generators/iterators memory layout
thank YOU!
At 3:50 the arrow pointed to 5 directly, but at 6:45 it pointed to a memory address which in turn points at 5.
Is this an actually difference or because you didn't want to complicate things and animated the easy way at 3:50?
3:50 example was using start+=step and 6:45 example (cell object) was using start=start+step, is this what is causing the difference?
I ran both examples and observed their co_freevars, closure, co_varnames and they look exactly the same. This makes me think the arrow at 3:50 should also be pointing at a memory address like 6:45 and start+=step vs start=start+step has no difference in this lesson.
If this is right, why complicate things using 2 different syntax, if wrong, what differences does += vs + cause in terms of closures?
At all times, Python stores pointers to actual objects and Python takes care of automatic dereferencing (explained in another video ruclips.net/video/0Om2gYU6clE/видео.html, also mentioned at 1:33 in the current video). At 6:45, instead of this one hop, there are two hops. Sometimes I just directly show the value because it's easy, requires less space on the screen, and that part is not what I will be explaining at that point in time.
With respect to '+=', there is a difference in how augmented arithmetic operators are handled(explained here ruclips.net/video/0Om2gYU6clE/видео.html). But for immutable objects, end result will be same. I just wanted to make it explicit.
@@sreekanthpr @Sreekanth Thanks for your reply, i have watched the other videos too, really grateful that you make such clear animations to help learners.
I understand the difference between += and + from that other video, but when it comes to this video, I still wish to reiterate my question.
1. Why is 3:50 1 hop and 6:45 2 hops?
2. Is the difference in 1. caused by writing start+=step vs start=start+step?
3. Is start+=step vs start=start+step used to demonstrate some other closure related concept in this video if it doesn't cause 1.?
Thanks!
There is no difference in start+=step vs start=start+step in closure. I just wanted to emphasize the right-hand side is evaluated first and it gets assigned back to the 'start' variable, that's why I chose to write it explicitly.
At 3:50 also there are 2 hops (the cell object exists). But the viewer is assumed to be not aware of the existence of cell objects at that point in time. At 06:32 is where I introduce this internal implementation detail.
@@sreekanthpr Hey, I got everything that you said except for the definition of "closure". It's unclear whether "inner" is a closure. If the enclosed function _(enclosed inside another function, in this case, "inner")_ contains free variables, only then it's a closure, right? I think there are some technical details that I am not able to manacle.
_PS: This is high-quality, quintessential content. I am looking forward to "Classes and Objects", "Decorators", "Metaclasses", etc. Also, you should start making videos on Data Structures and Algorithms with Python. I was always interested in the implementation details of CPython. May you achieve 10 million subscribers! I wish you the best of luck!_ :-)
@@nirajraut9408 Yes, the "inner" function is a closure if it it references any variable in its nonlocal scope. Those variables are called "free variables". So, closure is "function + free variables" (or "function + environment")
Next video might be on Python's import system covering things like module objects. After that I'm thinking of starting series on data structures.
too fast bro
I'm adding higher pauses between sentences in newer videos.
I needed for this 8 min video around 40 min to watch. I still don't get everything
I had to pause it every few seconds. It's just too quick and full of specialized terminology. Using pause by lector would be beneficial as it would give us time to assimilate the knowledge. I liked the drawings though. :)
Dude , When are you going to upload new video ?
yesterday :)
Video is nice but speak little slower.
Hindi me channel shuru kar ,,,nhi to nhi samzega kuch