Python tutorial: Variable Scopes & Namespaces - global/local/nonlocal | Explained with animations

preview_player
Показать описание
The variables you define in your Python code has a lexical scope where they are valid. These scopes are categorized as local, enclosing, global and built-in scopes.
Python language also provides a few keywords like global and nonlocal to modify the behaviour of its variable name resolution.
This video tries to explain how scopes and namespaces work in different scenarios.

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

I was having trouble understanding this concept before, but the way you explained it visually really helped me! Thank you for this video.

grifo_-cyan
Автор

Everyone should watch this. This is the Python that's just thrown at you without an explanation of how it works.

expansivegymnast
Автор

These videos are for serious learners, who wants to become professional programmers. Cannot think of anything better. Thanks and sincere gratitude for your rigorous scholarship that you have shared with us.

akmzahidulislam
Автор

Thank you so much! I hope YouTube recommends your channel more to more people!

rainforest
Автор

Simply brilliant. First time learning about built-in scope and nonlocal keyword

sidlas
Автор

This is so clear explaining that it's hard to not understand!

xiaoweilu
Автор

You are a genius. I at last understand global, local, nonlocal .. being a visual person. Your method of VISUAL teaching is UNIQUE. Do you have plans to produce full tutorials even on a paid plan. I would definately subscribe. Your work is simply EXELLENT. The best explanations i have come across so far. Thanks

apamwamba
Автор

Very good, thanks for your work producing this video. Taught me some new things and reminded me of some old things. I found the voice-over a little fast for easy comprehension so I switched the playback to 0.75 speed which, for me, worked better. Thanks again.

southof
Автор

finally, I understood the concept. thank you so much for explaining the 'local assignment entry masks the global namespace'. it makes a lot sense. Ta~~'

cb
Автор

You are the best, i will be more than happy to purchase your training if you make one.

miloudiriyad
Автор

Brilliant animation.
Thanks for this video and your efforts. I wish One day you'll obviously success for video

sajjadhossan
Автор

brilliant, love the way you tell things.

鱼也-rq
Автор

thanks a lot sreekanth.. i referred other materials as well. but your video explanations made the pint clear in one go.

gouthamkaranam
Автор

The concepts are explained in a beutiful manner ... I was just wondering what the rush was all about ?

debgandharghosh
Автор

love you channel, please not leave us, we want more videos

venentium
Автор

Perfect, i Couldn'tt understand it before thx

itzcallmepro
Автор

5:46 good lecture thx.
I have a question, at this point I think that outet function's namespace cannot have a value for "x" because outer function is not called(executed)

django
Автор

You mention at the end that nonlocal cannot be chained to global. I wish to ask about how nonlocal chain to each other.
In code below, why is outer's x finally printed to be 2 and not 1? outer's x seems to know inner2 (2 levels inside) has updated x too.
Does this mean inner1's nonlocal points to x in outer, and inner2's nonlocal points to inner1, therefore causing inner2's nonlocal to also point to outer, so all 3 scopes see the same x value that the address of x resolves to?
(I can see they are pointing to same id() if using mutables like list for x)


def outer():
x=0
def inner1():
nonlocal x
x+=1

def inner2():
nonlocal x
x+=1

inner2()
inner1()
print('x after:', x) # why is this not 1
outer()

Han-veuh
Автор

It helps alot, can't afford patreon or donation, put some ads in, we are okay with that <3. ty

pretamane
Автор

Hi Sreekanth your Python tutorials are indepth and awesome, keep it going. Please can you recommend any python book which teachs indepth python concepts.

NadeemRasoolpro