Scope of Variable Local and Global in Python || Lesson 28 || Python || Learning Monkey ||
#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Scope of Variable Local and Global in Python
In this class, we discuss the scope of variable local and global in python.
Local and Global Variable
The reader should have basics on functions. Click here.
Take an example and understand local and global variables, then go to the variable scope.
i=1
def f():
j=20
print(j+i)
def f1():
k=25
print(k+i)
f()
f1()
print(i)
From the above example variable, i is called the global variable.
The variable j defined in the function f is called the local variable.
What is the difference between local and global variables?
The global variable i in our example can be used and modified anywhere in our python script.
So the scope of the global variable is a complete python script.
We can use the local variable j only in the function f.
So the scope of the local variable is within the function.
From the above program, variable k is local to function f1.
The variable i, which is global in our example, is used in functions f and f1. We used the variable i out of the functions also.
Examples
Let’s take some examples to understand the concept of local and global variable scope better.
i=1
def f():
i=20
j=20
print(i+j)
f()
print(i)
Variable i is defined as both local and global in the above program.
This situation if we use the variable i inside the function. The function will check for local variables.
If the variable i not found in local variables. Then function checks the variable i in the global variables list.
Print(i+j) will display 40. because the variable i value is taken from local variable space.
Print (i) statement written outside the function. This statement will take variable i from global variable space.
Suppose the same variable name is used. The local variable is hiding the global variable.
Example 2:
i=1
def f():
i=20
l=20
print(i+l)
f()
print(i)
print(l)
From the program mentioned above.
The variable l is local to the function. Suppose we try to access the variable l outside the function. We get an error message.
Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists
Link for our website: https://learningmonkey.in
Follow us on Facebook @ https://www.facebook.com/learningmonkey
Follow us on Instagram @ https://www.instagram.com/learningmonkey1/
Follow us on Twitter @ https://twitter.com/_learningmonkey
Mail us @ [email protected]
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Scope of Variable Local and Global in Python || Lesson 28 || Python || Learning Monkey ||», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.