Python Tutorials - LEGB Rule | Local And Global Scope | global and non local Keyword

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ย. 2024
  • 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

ความคิดเห็น • 150

  • @sanjusmash3907
    @sanjusmash3907 ปีที่แล้ว +4

    Wow I have been watching lot of videos regarding LEGB but literally u saved me I understand through your video thanks a lot ❤🙌🙌🙌

  • @krishnarajput4125
    @krishnarajput4125 4 ปีที่แล้ว +10

    Nice explanation in my school I don't even know what they taught 😆

  • @TopperTroubles
    @TopperTroubles 3 ปีที่แล้ว +3

    Nice Explanation and easy to understand the scopes

  • @itunuraimi5530
    @itunuraimi5530 4 ปีที่แล้ว +5

    Best tutorial i have watched on youtube. Keep up the good work.

  • @caspajito3277
    @caspajito3277 3 ปีที่แล้ว +5

    YOU EXPLAINED VERY WELL MA'AM ..... GREAT PYTHON EXPERT😁👍👍

  • @ganeshsundar1484
    @ganeshsundar1484 7 หลายเดือนก่อน

    Very well explained, MOST UNDERRATED YT CHANNEL

  • @TheProblemSolvers38
    @TheProblemSolvers38 3 ปีที่แล้ว +1

    Thought you were a student when I first listened to your voice mam......And the explanation is ........No need to mention...❤️

  • @noArguments
    @noArguments 2 ปีที่แล้ว +1

    You voice is make me made programmer . I Love your voice 💓😻❤️❤️❤️.

  • @aliaradi8277
    @aliaradi8277 9 หลายเดือนก่อน

    You are a great teacher Amiul, wish u all the best.

  • @rajeshm8113
    @rajeshm8113 2 ปีที่แล้ว

    Voice is awesome so sharp it's pierce my ❤️ ... nice explanation 👌

  • @SHRINANGLIDARBAR
    @SHRINANGLIDARBAR 4 ปีที่แล้ว +2

    very informative lecture .Thanks
    God bless you always.

  • @harikrishnants8545
    @harikrishnants8545 4 ปีที่แล้ว +3

    Great work.Thanks a lot for sharing the information.

  • @anas5575
    @anas5575 5 ปีที่แล้ว +6

    Thank you mam. I'm learning Python this year for my board exam😀

    • @AmulsAcademy
      @AmulsAcademy  5 ปีที่แล้ว +1

      pleasure :)
      All the Best :)

    • @Aalekh_Chaudhary
      @Aalekh_Chaudhary ปีที่แล้ว

      Kaisa Gaya paper?

    • @anas5575
      @anas5575 ปีที่แล้ว

      @@Aalekh_Chaudhary I scored high marks in it😄

    • @Aalekh_Chaudhary
      @Aalekh_Chaudhary ปีที่แล้ว

      @@anas5575 are boi expect nahi kiya tu reply dega after 3 year

    • @anas5575
      @anas5575 ปีที่แล้ว

      @@Aalekh_Chaudhary hahaha 😂😂

  • @sandeepsrinivas7040
    @sandeepsrinivas7040 2 ปีที่แล้ว

    Thank's for the tutorial amulyaa and the concept delivery is crystal clear and again thanx

  • @gopinathan27
    @gopinathan27 5 ปีที่แล้ว +2

    You are teaching really awesome... Keep educate us !

    • @AmulsAcademy
      @AmulsAcademy  5 ปีที่แล้ว

      Thank you :)

    • @gopinathan27
      @gopinathan27 5 ปีที่แล้ว +1

      @@AmulsAcademy could you post a video about python multithreading?

    • @AmulsAcademy
      @AmulsAcademy  5 ปีที่แล้ว +1

      I will try :)

  • @sahasranamans8167
    @sahasranamans8167 2 ปีที่แล้ว

    mam you are simply excellent thanyou somuch for the vedios

  • @meralmaradia4774
    @meralmaradia4774 3 ปีที่แล้ว +1

    Really Helpful Amulya (y) , Thanks

  • @thirumala_reddy
    @thirumala_reddy 5 ปีที่แล้ว +2

    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...

  • @AmitSingh-fs2ot
    @AmitSingh-fs2ot 2 ปีที่แล้ว

    you are awesome in your explanation.

  • @anandavriksha9790
    @anandavriksha9790 4 ปีที่แล้ว +1

    Explanation is very nice madam

  • @prakashsaravanan6613
    @prakashsaravanan6613 3 ปีที่แล้ว +1

    Excellent expalanation sister , thanks a lot

  • @shivamrai6855
    @shivamrai6855 3 ปีที่แล้ว +2

    Thanks, didi for helping us........

  • @harivarsanpappu5142
    @harivarsanpappu5142 ปีที่แล้ว

    Great explanation

  • @yogeshkumarshankariya642
    @yogeshkumarshankariya642 4 ปีที่แล้ว +3

    thank you very much, ma'am, the way of teaching is very simple and smooth.

  • @vanshikanikhare5657
    @vanshikanikhare5657 3 ปีที่แล้ว +1

    Great ❤️ video ☺️

  • @slone2527
    @slone2527 2 ปีที่แล้ว

    explained in the best way.. thankyou🙌

  • @abhishekthakur9262
    @abhishekthakur9262 2 ปีที่แล้ว +1

    Gzb ki voice hn

  • @vaibhavtandale4233
    @vaibhavtandale4233 2 ปีที่แล้ว

    nice session di ..thank you so much

  • @javascriptwar9525
    @javascriptwar9525 4 ปีที่แล้ว

    Your tutorial about LEGB rule is very helpfull ....☺❤

  • @paulprasadbabu
    @paulprasadbabu หลายเดือนก่อน

    thank you madam, good explanation

  • @VivekKBangaru
    @VivekKBangaru 4 ปีที่แล้ว +1

    NIce Video Thanks

  • @mohdzohaibmohdzohaib4218
    @mohdzohaibmohdzohaib4218 2 ปีที่แล้ว

    Thanks mam video banane k liye

  • @randomclips6905
    @randomclips6905 4 ปีที่แล้ว +1

    you made to understand everything about scope thank you so much(:

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว

      Happy to hear that!

    • @randomclips6905
      @randomclips6905 4 ปีที่แล้ว

      @@AmulsAcademy ty can you please teach machine learning algorithms?

  • @fahedpiash6257
    @fahedpiash6257 4 ปีที่แล้ว +1

    Wow how awesome ur explanation is 😍

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว +1

      Thank you so much 😀

  • @greenpanther2892
    @greenpanther2892 4 ปีที่แล้ว +1

    Amazing explaination ,I got every point

  • @bharathmrperfect7756
    @bharathmrperfect7756 2 ปีที่แล้ว

    good job

  • @anuragsingh2517
    @anuragsingh2517 3 ปีที่แล้ว +1

    Nice explaination mam super

    • @AmulsAcademy
      @AmulsAcademy  3 ปีที่แล้ว +1

      Thanks a lot :)

    • @anuragsingh2517
      @anuragsingh2517 3 ปีที่แล้ว

      @@AmulsAcademy Mam can you make video on random function and random module. How to solve random function.
      Mam please make video on this topic

  • @anmolpatil8894
    @anmolpatil8894 4 ปีที่แล้ว +1

    Great explanation specially the scope...thank u mam

  • @jess7
    @jess7 ปีที่แล้ว

    thanks man! keep it up!

  • @KOTHAABHISHEK
    @KOTHAABHISHEK 3 ปีที่แล้ว +1

    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

    • @AmulsAcademy
      @AmulsAcademy  3 ปีที่แล้ว

      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 😊

    • @KOTHAABHISHEK
      @KOTHAABHISHEK 3 ปีที่แล้ว

      @@AmulsAcademy tq very much
      I will try this

  • @afseena4613
    @afseena4613 ปีที่แล้ว

    thank u so much well explained

  • @kareemsaheb5438
    @kareemsaheb5438 4 ปีที่แล้ว +1

    Simply superb

  • @Balajionceagain
    @Balajionceagain 4 ปีที่แล้ว +1

    Thanks for the explanation 👍🏻

  • @carlabest1257
    @carlabest1257 3 ปีที่แล้ว +1

    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...

  • @rumagoswami3272
    @rumagoswami3272 4 ปีที่แล้ว +1

    superb explanation maam

  • @dasanirban91
    @dasanirban91 4 ปีที่แล้ว +1

    Awesome tutorial.Clearly explained with examples. Thank you.

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว +1

      Glad it was helpful! :)

  • @s2613
    @s2613 5 ปีที่แล้ว +1

    Thanks for clarification on topics 😊

  • @prasanth123cet
    @prasanth123cet 3 ปีที่แล้ว +1

    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?

    • @AmulsAcademy
      @AmulsAcademy  3 ปีที่แล้ว

      Yes because it is global you can access it inside function body😊

  • @danielcharles6088
    @danielcharles6088 2 ปีที่แล้ว

    Awesome tutorial thank you so much ma'am.

  • @sivanamala7279
    @sivanamala7279 5 ปีที่แล้ว +1

    very nice explanation..keep up the good work

  • @SalmanKhan-pu6sc
    @SalmanKhan-pu6sc 4 ปีที่แล้ว +1

    Thanks ur vdo was quite helpful

  • @mdtasawarrahmansaumik716
    @mdtasawarrahmansaumik716 2 ปีที่แล้ว

    great!!!

  • @shraddhap
    @shraddhap 4 ปีที่แล้ว +1

    Thank you for the tutorial

  • @gurneetkaur1498
    @gurneetkaur1498 4 ปีที่แล้ว +1

    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?

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว

      Give me the program , I will check :)

  • @ceciliaagava7022
    @ceciliaagava7022 2 ปีที่แล้ว

    Now I get it, thanks 👍🏾

  • @sourcloud_
    @sourcloud_ 2 ปีที่แล้ว

    thank you ma'am!

  • @maaaaaass
    @maaaaaass 3 ปีที่แล้ว +1

    Nice explanation,in which company r u working?

    • @AmulsAcademy
      @AmulsAcademy  3 ปีที่แล้ว +1

      Thank you :)
      I am a Full time TH-camr :)

    • @KOTHAABHISHEK
      @KOTHAABHISHEK 3 ปีที่แล้ว

      @@AmulsAcademy wow great

  • @dipeshupadhyay5583
    @dipeshupadhyay5583 4 ปีที่แล้ว +1

    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?

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว

      First local then enclosed then global lastly built_in
      :)

  • @aditinnaik00
    @aditinnaik00 4 ปีที่แล้ว +1

    thank you so much ma'am. The concept has been well-explained with required examples. Thank you for helping us.

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว

      It's my pleasure :)

    • @kalyan64
      @kalyan64 4 ปีที่แล้ว

      Hiii amrutha

    • @kalyan64
      @kalyan64 4 ปีที่แล้ว

      Small help from u

  • @vinnapshot7961
    @vinnapshot7961 2 ปีที่แล้ว

    Best ever

  • @chandramouli8831
    @chandramouli8831 5 ปีที่แล้ว +2

    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()

    • @AmulsAcademy
      @AmulsAcademy  5 ปีที่แล้ว +7

      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.
      :)

    • @chandramouli8831
      @chandramouli8831 5 ปีที่แล้ว +1

      @@AmulsAcademy Thanks for clarifying. Much appreciated.. keep it up.

  • @andijchitrakar463
    @andijchitrakar463 2 ปีที่แล้ว

    THANK YOU 😍

  • @preethisupraja1238
    @preethisupraja1238 5 ปีที่แล้ว +1

    I like your videos😘😘. Is this complete python tutorial?

    • @AmulsAcademy
      @AmulsAcademy  5 ปีที่แล้ว +1

      Thank you :)
      basic concepts are covered.
      Now doing advanced topics :)

    • @preethisupraja1238
      @preethisupraja1238 5 ปีที่แล้ว +1

      Thanks for your reply 😊😊😊

  • @prasanthkumar5638
    @prasanthkumar5638 3 ปีที่แล้ว +1

    Thankyou.......

  • @pdi-sb9vk
    @pdi-sb9vk 4 ปีที่แล้ว +1

    very good teaching mam. Thank you.

  • @kakhil1843
    @kakhil1843 3 ปีที่แล้ว +1

    is global varible is define in outside the function.

  • @yvng4697
    @yvng4697 3 ปีที่แล้ว +1

    Thank u so much!!

  • @prabhapro3663
    @prabhapro3663 4 ปีที่แล้ว +1

    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

    • @prabhapro3663
      @prabhapro3663 4 ปีที่แล้ว

      please reply mam.sorry if there is anything wrong in my question.please correct it

    • @AmulsAcademy
      @AmulsAcademy  4 ปีที่แล้ว

      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()

  • @pavithran7776
    @pavithran7776 3 ปีที่แล้ว

    How it is search the variable x in built in scope?

  • @amizbox
    @amizbox 2 ปีที่แล้ว

    thank you :)

  • @surajgawade262
    @surajgawade262 4 ปีที่แล้ว +1

    NIce mam.

  • @Nothing-sh2pw
    @Nothing-sh2pw 3 ปีที่แล้ว +1

    Wow

  • @postnetworkacademy
    @postnetworkacademy 4 ปีที่แล้ว +1

    Clearly explained, thank you very much.

  • @susantadas4423
    @susantadas4423 2 ปีที่แล้ว

    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

    • @kprasanna79
      @kprasanna79 ปีที่แล้ว +1

      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.

  • @baderalrahamneh8671
    @baderalrahamneh8671 5 ปีที่แล้ว +1

    Perfect.

  • @nogame-nolife8537
    @nogame-nolife8537 4 ปีที่แล้ว +1

    like it

  • @janakiyeluripati6368
    @janakiyeluripati6368 4 ปีที่แล้ว

    Hello madam, can you make some exercises (python problems) of nested functions

  • @sqlsql4304
    @sqlsql4304 4 ปีที่แล้ว

    At 2:43 you have to change the order to LEGB

  • @yanamadalaharishkumar5041
    @yanamadalaharishkumar5041 4 ปีที่แล้ว

    9:57 its we can access enclosing var in local scope ?

    • @ans7452
      @ans7452 3 ปีที่แล้ว

      Yes you can using nonlocal keyword...

  • @mingshenggu2078
    @mingshenggu2078 4 ปีที่แล้ว

    Where did your English learn from? Are you Indian people?

  • @BilluComedian
    @BilluComedian 3 ปีที่แล้ว

    “The reason I talk to myself is because I’m the only one whose answers I accept.”
    -

  • @kalyan64
    @kalyan64 4 ปีที่แล้ว +1

    Hii amulya small help from u

  • @amolpisode4901
    @amolpisode4901 3 ปีที่แล้ว

    Not understood

  • @amangupta-zg2yr
    @amangupta-zg2yr 5 ปีที่แล้ว

    you make this so difficult , you can explain better

  • @blackangel7877
    @blackangel7877 5 ปีที่แล้ว

    koi

  • @blackangel7877
    @blackangel7877 5 ปีที่แล้ว

    engadi porandha punda