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
I want to address a question that you may or may not have but it's something that's taken me years to
understand and that is why not just have everything as global variables.
I mean all this confusion of who has access to who.
How easy would it be if everything was just on the main page.
All our information all the data on our global scope so that everything has access to everything.
Wouldn't that be easier and you'd be kind of right.
I mean that would make all this headache go away.
Right.
But you have to remember that machines don't have infinite power don't have infinite CPR you don't have
infinite memory they all have limited resources.
And as programmers we have to be conscious of what resources we use because sometimes that can cost
us money.
Sometimes that can crash our computers and scope is a great demonstration of this.
For example this code right here when this function is run we're creating technically just one location
in memory for the x variable.
So we have that bookshelf in our computer that is X. That's pointing to local when we actually call
this function.
And then when we say non-local here Well we're saying just don't create another bookshelf for us.
Just use the one that we already have and assign it non-local if we didn't have this line by the time
we get to line seven.
We've placed in memory x equals two local and x equals two non-local.
So we have two locations now in memory.
Now this isn't a big deal because well in this day and age we do have a lot of memory but as programs
get larger and larger this does become a bit of a problem.
OK.
But what about a function.
I mean we learned that functions allow us to not repeat ourselves and being able to call out our multiple
times.
But another good use of functions is that once we call this function and all of this is done the computer
and the Python interpreter specifically destroys all this memory that is once we finish with the outer
function.
I can't really call print x here.
It's going to give me an error.
It's going to say I have no idea what X is and why is that it's because after we call this function
the python will be called the garbage collector is going to say hey it looks like we're done with this
function.
And I see that this x variable well in this x variable we're not gonna use because we're done with this
function.
So I'm going to collect that garbage and then just throw it out.
So I'm going to empty that memory cupboard so that other resources or other programs can use that.
And that is a really nice feature where python just automatically removes these for you so that you
don't clog up the computer's memory and that's why scope is useful.
We don't have to think about it in such detail like I've mentioned it but it's nice to know that it's
there so that your programs don't hog up a lot of memory and they can run efficiently.
This is a bit of an advance topic but I did want to include it in here so that you can think about why
programs are designed the way they are.
All right let's stop talking now.
I'll see you in the next video by.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.