RUVIDEO
Поделитесь видео 🙏

Nested Functions and Non Local Variables in Python || Lesson 33 || Python || Learning Monkey ||

📁 Обучение 👁️ 16 📅 02.12.2023

#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Nested Functions and Non Local Variables in Python
In this class, we discuss Nested Functions and Non Local Variables in Python.
Nested Functions
The reader should have prior knowledge of local and global variables in python. Click here.
Let’s take an example and understand the concept.

First, we refresh the concept of a local and global variable.
a=1
def f():
global a
a=5
print("local variable")
print(a)
f()
print("global variable")
print(a)

In the above program, we defined a global variable a.
If we want to assign a new value to the global variable a, in the function f., we use the keyword global.
In the function, we defined global a. this statement allows the function not to create local variable a.
Nested Functions:
Function within the function we call nested function.

Example 1
a=1
def f():
b=6
c=7
def f1():
d=40
print("global value inside nested function",a)
print(" value from above function",b)
print("local value of nested function",d)
nonlocal c
c=20
f1()
print(" non local updated value",c)
print(b)
# d is local to f1

f()
print(a)

In the above program, a is a global variable.
We had a function f1 inside the function f.
Variables b and c are defined within function f. we can use variables b and c inside function f anywhere. I.e., in the function, f1 too.
Variable d is defined inside function f1. Variable d is local to function f1.ie we can not use outside the function f1.
In function f1, we defined nonlocal c. meaning, should take the variable c from function f.
Do not create a new local variable in function f1.
Now function f1 considers variable c as a nonlocal variable.
This nonlocal keyword is used similar to the global keyword used in our first example.
The variable d, local to the f1 function, can not be used inside function f.
With this knowledge, analyze the program output given above.
Suppose function f tries to use the variable d. It will get an error. It was shown in the program below.
Example 2
a=1
def f():
b=6
c=7
def f1():
d=40
print("global value inside nested function",a)
print(" value from above function",b)
print("local value of nested function",d)
nonlocal c
c=20
f1()
print(" non local updated value",c)
print(b)
print(d)
# d is local to f1
f()
print(a)


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, чтобы посмотреть онлайн «Nested Functions and Non Local Variables in Python || Lesson 33 || Python || Learning Monkey ||», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.