Python Tutorials - LEGB Rule | Local And Global Scope | global and non local Keyword
HTML-код
- Опубликовано: 5 янв 2019
- In this Python programming video tutorial we will learn about different variable scope and legb rule in detail.
To understand the decorators we need to learn namespace and variable scope.
Generally namespace (sometimes also called a context) is a naming system for making names unique to avoid ambiguity.
Namespaces in Python are implemented as Python dictionaries, this means it is a mapping from names (keys) to objects (values).
Variable scope refers to the visibility of variables. In other words, which parts of your program can see or use it.
There are 4 types of scopes in python in this tutorial we will discuss about that in detail.
Local scope refers to variables defined in current function.
Enclosing - names defined inside any and all enclosing functions.
Global - names defined at the top-level of a module. Each module brings with it a new global scope.
Built-in - names built-in to the Python language through the special builtins module.
Namespace and Variable Scope:
• Python Tutorials - Nam...
#PythonProgramming #Decorators
For more free tutorials on computer programming
/ amulsacademy
/ amulsacademy
Wow I have been watching lot of videos regarding LEGB but literally u saved me I understand through your video thanks a lot ❤🙌🙌🙌
Nice explanation in my school I don't even know what they taught 😆
Nice Explanation and easy to understand the scopes
Thank you :)
Very well explained, MOST UNDERRATED YT CHANNEL
Best tutorial i have watched on youtube. Keep up the good work.
Thank you :)
YOU EXPLAINED VERY WELL MA'AM ..... GREAT PYTHON EXPERT😁👍👍
Thank you! :)
You voice is make me made programmer . I Love your voice 💓😻❤️❤️❤️.
Your tutorial about LEGB rule is very helpfull ....☺❤
explained in the best way.. thankyou🙌
Great work.Thanks a lot for sharing the information.
My pleasure :)
Awesome tutorial thank you so much ma'am.
NIce Video Thanks
very informative lecture .Thanks
God bless you always.
Always welcome :)
Thank's for the tutorial amulyaa and the concept delivery is crystal clear and again thanx
You are a great teacher Amiul, wish u all the best.
you are awesome in your explanation.
Great explanation
mam you are simply excellent thanyou somuch for the vedios
Great explanation specially the scope...thank u mam
My pleasure 😊
Voice is awesome so sharp it's pierce my ❤️ ... nice explanation 👌
Amazing explaination ,I got every point
Thank you :)
Thanks for clarification on topics 😊
Welcome :)
thanks man! keep it up!
thank u so much well explained
nice session di ..thank you so much
Thanks mam video banane k liye
Thanks for the explanation 👍🏻
My pleasure :)
Now I get it, thanks 👍🏾
Thanks ur vdo was quite helpful
My Pleasure :)
great!!!
Wow how awesome ur explanation is 😍
Thank you so much 😀
Thought you were a student when I first listened to your voice mam......And the explanation is ........No need to mention...❤️
Thanks a lot 😊
good job
Gzb ki voice hn
Really Helpful Amulya (y) , Thanks
Pleasure 😊
Simply superb
Thank you :)
you made to understand everything about scope thank you so much(:
Happy to hear that!
@@AmulsAcademy ty can you please teach machine learning algorithms?
Thank you for the tutorial
You’re welcome 😊
Great ❤️ video ☺️
Thank you 😊
THANK YOU 😍
You are teaching really awesome... Keep educate us !
Thank you :)
@@AmulsAcademy could you post a video about python multithreading?
I will try :)
Excellent expalanation sister , thanks a lot
You are most welcome :)
thank you very much, ma'am, the way of teaching is very simple and smooth.
Pleasure :)
thank you ma'am!
thank you :)
Clearly explained, thank you very much.
Glad it was helpful!
Explanation is very nice madam
Thank you so much :)
Awesome tutorial.Clearly explained with examples. Thank you.
Glad it was helpful! :)
Thank u so much!!
You're welcome! :)
super explanation about scopes and rules amulya garu...thank u so much ji...can you please make how to find bugs and which tool is best for it in python...
Thank you :)
Perfect.
Thank you :)
Thanks, didi for helping us........
Most welcome :)
superb explanation maam
Glad you liked it!
Best ever
very nice explanation..keep up the good work
Thankyou.......
Pleasure :)
Thank you mam. I'm learning Python this year for my board exam😀
pleasure :)
All the Best :)
Kaisa Gaya paper?
@@Cold_breeze7 I scored high marks in it😄
@@anas5575 are boi expect nahi kiya tu reply dega after 3 year
@@Cold_breeze7 hahaha 😂😂
thank you so much ma'am. The concept has been well-explained with required examples. Thank you for helping us.
It's my pleasure :)
Hiii amrutha
Small help from u
Nice explaination mam super
Thanks a lot :)
@@AmulsAcademy Mam can you make video on random function and random module. How to solve random function.
Mam please make video on this topic
NIce mam.
Thank you :)
thanks for the lovely explanation i have a doubt abt how you explain in last lebg rule it was the non local then local then global?
First local then enclosed then global lastly built_in
:)
Wow
Thank you :)
Hello madam, can you make some exercises (python problems) of nested functions
like it
Thank you :)
Hi Amulya, In your third explanation for Enclosed scope, am unable to define the function inner after z=4, while printing am getting an error that inner is not defined. Can you help me here?
Give me the program , I will check :)
very good teaching mam. Thank you.
It's my pleasure :)
How it is search the variable x in built in scope?
I like your videos😘😘. Is this complete python tutorial?
Thank you :)
basic concepts are covered.
Now doing advanced topics :)
Thanks for your reply 😊😊😊
Hi...
I am able to update the Enclosed variable inside the function as well as outside.
Here is the code without mentioning nonlocal, could you please clarify
x=10
def fun():
y=15
def inner():
z=20
print(y+1)
print(y+1)
inner()
fun()
In the program you are not changing the y value, you are just printing y+1 value.
when you write y=y+1, here you are changing the y value.
:)
@@AmulsAcademy Thanks for clarifying. Much appreciated.. keep it up.
I created a list globally and wrote a function to sort the list. When the function runs, sorting happens on the global variable. I mean if I access the list outside the function, it appears sorted. why?
Yes because it is global you can access it inside function body😊
9:57 its we can access enclosing var in local scope ?
Yes you can using nonlocal keyword...
Nice explanation,in which company r u working?
Thank you :)
I am a Full time RUclipsr :)
@@AmulsAcademy wow great
is global varible is define in outside the function.
Yes :)
For example if we have x in global, enclosed, and local
By default it will print local value only
But i want to print enclosed/global value
How can we do that
I know 1 method globals() to print global value
But how to print enclosed value
Try this
x=100
def f():
x=200
nonlocals= locals()
def f1():
x=300
x = nonlocals["x"]
print(x)
f1()
f()
You can use globals() for global value 😊
@@AmulsAcademy tq very much
I will try this
a = 5
def function():
a=10
print('aE',a)
def inner():
a=15
print('al', a)
inner()
function()
----------------output-------------
aE 10
al 15
in this case it print the enclose value 1st then it come to local scope , but according to the rule LEGB first it should be print local scope variable. kindly rectify me if i'm in wrong
Susant, You are calling the inner() inside the function(), thats why aE 10 is printing first. aE is local to function() and al is local to inner(). In both the case Local is printing as priority.
At 2:43 you have to change the order to LEGB
“The reason I talk to myself is because I’m the only one whose answers I accept.”
-
y=5
def outer():
x=10
def inner():
z=16
nonlocal x
x=x+1
print(x)
print(z)
inner()
print(x)
outer()
11
16
11
hello madam.! in this program i had modified 'x' in the local scope and it is done but why it is changed in the enclosed scope
please reply mam.sorry if there is anything wrong in my question.please correct it
Because you are calling inner() before print(x) so it will modify x value.
You can try this:
y=5
def outer():
x=10
def inner():
z=16
nonlocal x
x=x+1
print("x value inside inner:",x)
print("z value:",z)
print("x value outside inner:",x)
inner()
outer()
Python's scoping rules is not LEGB - but rather LEMB - the "M" stands for module. Python has no true global variables - or global functions for that matter. Python does not have truly "global" variables. Any variable defined in one module (outside of a function) must be imported into any other module that wants to use it. This is the source of a huge misunderstanding. The use of "global" in python is at odds with most other programming language - making python quirky in many respects. I do not recommend python as a first language. The Microsoft languages in Visual Studio are a vast improvement - in my view...
Hii amulya small help from u
How can I help you?
Where did your English learn from? Are you Indian people?
you make this so difficult , you can explain better
koi
Not understood
engadi porandha punda