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

Комментарии • 149

  • @sanjusmash3907
    @sanjusmash3907 11 месяцев назад +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

  • @ganeshsundar1484
    @ganeshsundar1484 4 месяца назад

    Very well explained, MOST UNDERRATED YT CHANNEL

  • @itunuraimi5530
    @itunuraimi5530 3 года назад +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😁👍👍

  • @noArguments
    @noArguments 2 года назад +1

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

  • @javascriptwar9525
    @javascriptwar9525 4 года назад

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

  • @slone2527
    @slone2527 Год назад

    explained in the best way.. thankyou🙌

  • @harikrishnants8545
    @harikrishnants8545 4 года назад +3

    Great work.Thanks a lot for sharing the information.

  • @danielcharles6088
    @danielcharles6088 2 года назад

    Awesome tutorial thank you so much ma'am.

  • @VivekKBangaru
    @VivekKBangaru 4 года назад +1

    NIce Video Thanks

  • @SHRINANGLIDARBAR
    @SHRINANGLIDARBAR 4 года назад +2

    very informative lecture .Thanks
    God bless you always.

  • @sandeepsrinivas7040
    @sandeepsrinivas7040 2 года назад

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

  • @aliaradi8277
    @aliaradi8277 6 месяцев назад

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

  • @AmitSingh-fs2ot
    @AmitSingh-fs2ot 2 года назад

    you are awesome in your explanation.

  • @harivarsanpappu5142
    @harivarsanpappu5142 Год назад

    Great explanation

  • @sahasranamans8167
    @sahasranamans8167 2 года назад

    mam you are simply excellent thanyou somuch for the vedios

  • @anmolpatil8894
    @anmolpatil8894 4 года назад +1

    Great explanation specially the scope...thank u mam

  • @rajeshm8113
    @rajeshm8113 Год назад

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

  • @greenpanther2892
    @greenpanther2892 3 года назад +1

    Amazing explaination ,I got every point

  • @s2613
    @s2613 5 лет назад +1

    Thanks for clarification on topics 😊

  • @jess7
    @jess7 Год назад

    thanks man! keep it up!

  • @afseena4613
    @afseena4613 Год назад

    thank u so much well explained

  • @vaibhavtandale4233
    @vaibhavtandale4233 2 года назад

    nice session di ..thank you so much

  • @mohdzohaibmohdzohaib4218
    @mohdzohaibmohdzohaib4218 Год назад

    Thanks mam video banane k liye

  • @Balajionceagain
    @Balajionceagain 4 года назад +1

    Thanks for the explanation 👍🏻

  • @ceciliaagava7022
    @ceciliaagava7022 2 года назад

    Now I get it, thanks 👍🏾

  • @SalmanKhan-pu6sc
    @SalmanKhan-pu6sc 4 года назад +1

    Thanks ur vdo was quite helpful

  • @mdtasawarrahmansaumik716
    @mdtasawarrahmansaumik716 Год назад

    great!!!

  • @fahedpiash6257
    @fahedpiash6257 4 года назад +1

    Wow how awesome ur explanation is 😍

  • @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...❤️

  • @bharathmrperfect7756
    @bharathmrperfect7756 Год назад

    good job

  • @abhishekthakur9262
    @abhishekthakur9262 2 года назад +1

    Gzb ki voice hn

  • @meralmaradia4774
    @meralmaradia4774 3 года назад +1

    Really Helpful Amulya (y) , Thanks

  • @kareemsaheb5438
    @kareemsaheb5438 4 года назад +1

    Simply superb

  • @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?

  • @shraddhap
    @shraddhap 4 года назад +1

    Thank you for the tutorial

  • @vanshikanikhare5657
    @vanshikanikhare5657 2 года назад +1

    Great ❤️ video ☺️

  • @andijchitrakar463
    @andijchitrakar463 Год назад

    THANK YOU 😍

  • @gopinathan27
    @gopinathan27 5 лет назад +2

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

  • @prakashsaravanan6613
    @prakashsaravanan6613 3 года назад +1

    Excellent expalanation sister , thanks a lot

  • @yogeshkumarshankariya642
    @yogeshkumarshankariya642 4 года назад +3

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

  • @sourcloud_
    @sourcloud_ 2 года назад

    thank you ma'am!

  • @amizbox
    @amizbox 2 года назад

    thank you :)

  • @postnetworkacademy
    @postnetworkacademy 4 года назад +1

    Clearly explained, thank you very much.

  • @anandavriksha9790
    @anandavriksha9790 3 года назад +1

    Explanation is very nice madam

  • @dasanirban91
    @dasanirban91 3 года назад +1

    Awesome tutorial.Clearly explained with examples. Thank you.

  • @yvng4697
    @yvng4697 3 года назад +1

    Thank u so much!!

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

  • @baderalrahamneh8671
    @baderalrahamneh8671 5 лет назад +1

    Perfect.

  • @shivamrai6855
    @shivamrai6855 3 года назад +2

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

  • @rumagoswami3272
    @rumagoswami3272 4 года назад +1

    superb explanation maam

  • @vinnapshot7961
    @vinnapshot7961 2 года назад

    Best ever

  • @sivanamala7279
    @sivanamala7279 4 года назад +1

    very nice explanation..keep up the good work

  • @prasanthkumar5638
    @prasanthkumar5638 3 года назад +1

    Thankyou.......

  • @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 :)

    • @Cold_breeze7
      @Cold_breeze7 Год назад

      Kaisa Gaya paper?

    • @anas5575
      @anas5575 Год назад

      @@Cold_breeze7 I scored high marks in it😄

    • @Cold_breeze7
      @Cold_breeze7 Год назад

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

    • @anas5575
      @anas5575 Год назад

      @@Cold_breeze7 hahaha 😂😂

  • @aditinnaik00
    @aditinnaik00 4 года назад +1

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

  • @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

  • @surajgawade262
    @surajgawade262 4 года назад +1

    NIce mam.

  • @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
      :)

  • @Nothing-sh2pw
    @Nothing-sh2pw 3 года назад +1

    Wow

  • @janakiyeluripati6368
    @janakiyeluripati6368 4 года назад

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

  • @nogame-nolife8537
    @nogame-nolife8537 3 года назад +1

    like it

  • @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 :)

  • @pdi-sb9vk
    @pdi-sb9vk 4 года назад +1

    very good teaching mam. Thank you.

  • @pavithran7776
    @pavithran7776 3 года назад

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

  • @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 😊😊😊

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

  • @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😊

  • @yanamadalaharishkumar5041
    @yanamadalaharishkumar5041 4 года назад

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

    • @ans7452
      @ans7452 3 года назад

      Yes you can using nonlocal keyword...

  • @maaaaaass
    @maaaaaass 3 года назад +1

    Nice explanation,in which company r u working?

    • @AmulsAcademy
      @AmulsAcademy  3 года назад +1

      Thank you :)
      I am a Full time RUclipsr :)

    • @KOTHAABHISHEK
      @KOTHAABHISHEK 3 года назад

      @@AmulsAcademy wow great

  • @kakhil1843
    @kakhil1843 3 года назад +1

    is global varible is define in outside the function.

  • @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

  • @susantadas4423
    @susantadas4423 Год назад

    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.

  • @sqlsql4304
    @sqlsql4304 4 года назад

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

  • @BilluComedian
    @BilluComedian 3 года назад

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

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

  • @carlabest1257
    @carlabest1257 2 года назад +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...

  • @kalyan64
    @kalyan64 4 года назад +1

    Hii amulya small help from u

  • @mingshenggu2078
    @mingshenggu2078 4 года назад

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

  • @amangupta-zg2yr
    @amangupta-zg2yr 5 лет назад

    you make this so difficult , you can explain better

  • @blackangel7877
    @blackangel7877 4 года назад

    koi

  • @amolpisode4901
    @amolpisode4901 3 года назад

    Not understood

  • @blackangel7877
    @blackangel7877 4 года назад

    engadi porandha punda