Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.