Python 3 Tutorial: How To Use Local Variables

preview_player
Показать описание
Be sure to like, share and comment to show your support for our tutorials.

=======================================
======================================

Now that we understand what a function is, what it does and how it is structured we need to dive into local variables. There is not much to a local variable once you have an understanding what a local variable is.+

What Is A Local Variable?
A local variable is a variable that lives inside a function. This variable is only available to the code within the function. We are unable to call the variable outside the function. This variable only exists when the function is ran. Even if we use our local variable to return an object that variable is not available to the code outside the variable.

When we return an object to the receiver we are only sending back the object that was created by the function run. It is important to note as well that a local variable will not remember the object that it just represent on the last function run this means anytime we need an object from a function that function must rerun for every ask.

Do not get confused if a variable is assigned outside a function this is referred to as global variable and this variable is available to all the code. We will discuss global variables more in a future tutorial.
Рекомендации по теме
Комментарии
Автор

what is static variable equivalent in python?

phantomhieve