All language subtitles for 35. nonlocal Keyword

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Oh boy there's some code on the screen and it looks terribly confusing.

This is an example of a really convoluted complicated function that you would never write but it'll

be good for exercise purposes.

And we're talking specifically about this right here called non local.

It's actually a new keyword in Python 3.

And as you can see my ripple doesn't even notice it so it doesn't even highlighted in blue because it

is a new feature.

But I do want to talk to you about it and let you know what it does the non local keyword is used to

refer to this part.

This parent local it's a way for us to say hey I want to use a variable that is not a global variable

but is outside of the scope of my function so based on that definition try and pause the video and see

what this function might do.

I'll run it right now and then go through the code if I click Run.

This is what we get so let's talk about this.

We have an outer function and then we call the outer function.

So the Python interpreter is going to go and say All right we have an x variable that is local to the

outer function and then inside of here we're going to define an inner function.

Another function and then here before we even call that we jumped in line nine and say All right call

inter function.

We come back and we say hey line five I want to use non local x.

What does that mean.

Well I want to use this x variable because it's non local.

That is I don't want to create a new x variable.

I want to jump up the scope to my parents scope my parent local and grab whatever you find in there

as long as it's not global variable.

Any parent will do.

I want to grab that non-local.

So now this ex is referring to the outer function here.

So when we say X equals non-local we're assigning this new string and replacing this local so that when

we print inner x we get non-local but also when we print the outer X we've modified this outer scope

with the non-local keyword.

So that becomes non local as well.

If I remove this line and let's comment it out and I click Run you see the difference.

Now we have the inner non-local but then the outer local hasn't been modified because this is a new

variable.

Again I argue that this actually makes your code more complicated than it needs to be.

So there are special cases where you might want to use this but if you can try to make your code predictable

where you can avoid using things like non-local and global mind you they are there for a reason because

they are useful in some situation.

With that said keep in mind make your code predictable make your code clean and I'll see you in the

next video.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.