What is a CLOSURE and how to use it in Python?

preview_player
Показать описание
After this video, you are able to describe a closure, can write one in Python and decide if it is useful for you in your code.

C H A P T E R S
0:33 The problem with changing a global variable from a function
1:47 Use a closure to encapsulate the global variable
3:00 Where the name closure comes from
3:28 Comparing closures to a class with a single function

M Y O N L I N E T R A I N I N G

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

This is the best explanation so far. Everybody is telling how to use them but no one explains WHY to use them.. So after all they are for encapsulation.

swordlion
Автор

After going through tons of tutorials of tech dudes who make videos just to make money and not to really teach newbies, this one really taught me. Thank you.

MM-oqlb
Автор

This is the clearest explanation on YouTube by far. keeping up the good work from Hong Kong.

DylanASD
Автор

Great stuff. That's exactly what I was after for some time now! I have been reading the online tutorials about closures, which give you same examples over and over, so that you know how it's done, but they leave you with no clue to why would you actually do it.
This is the perfect explanation that i was after. Thanks a lot! I have subscribed to your channel! Keep it up, please!

Sergio-pdsh
Автор

I finally get it, and this will help with an issue I’m always running into. Thank you!

thetutorialdoctor
Автор

Thanks bro, just as simple explanation as python

azizbekibnhamid
Автор

Was having hard time with closures, this video explains it clearly. Thank you!

kamranzamanni
Автор

definitely the best and short explanation i found so far, good work bro

zhzolwu
Автор

Thank you! Third video on the subject and first now I got it.

deonyz
Автор

I never thought about closure can actually mimic a class. Or can I say classes are just syntactic sugar for closures?

iwatchtvwithportal
Автор

wow. never seen such an explanation. thanks a lot

devworks
Автор

I still don't get it. How do you call enter_num with a parameter, even it refers to a function enter_number_outer, which has no parameter?

omarozt
Автор

1:10 Why don't you need the global keyword inside the function?
numbers = []
def enter_number(x):
global numbers
....

johnaweiss