Python Tutorial: Variable Scope – Understanding the LEGB rule and global/nonlocal statements

///Python Tutorial: Variable Scope – Understanding the LEGB rule and global/nonlocal statements

Python Tutorial: Variable Scope – Understanding the LEGB rule and global/nonlocal statements

FavoriteLoadingAdd to favorites

In this Python Tutorial, we will be going over variable scope in Python. Scope is important because we need to understand it in just about every program we write. It allows us to understand where our variables can be seen from within our program and also what values these variables hold. It also helps with debugging, because scope is a common problem when errors are thrown. Let’s get started.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

source

By |2019-12-14T00:33:19+00:00December 14th, 2019|Python Video Tutorials|22 Comments

22 Comments

  1. pranav pawar December 14, 2019 at 12:33 am - Reply

    Thanks Corey for uploading such a wonderful playlist

  2. Anil Gopi December 14, 2019 at 12:33 am - Reply

    I've been binging on these videos. This 20 min video will save me hours of headache.

  3. Dinuka Rajapakse December 14, 2019 at 12:33 am - Reply

    Your teaching skills are truly amazing! I understood everything crystal clear! Thank you so much!

  4. Internetverbraucher December 14, 2019 at 12:33 am - Reply

    I have a question about the nested inner() function: can i call the inner function from the global scale without having it inside a class? something like outer.inner() ?

  5. Soumya Ranjan Das December 14, 2019 at 12:33 am - Reply

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  6. Tobias sjöholm December 14, 2019 at 12:33 am - Reply

    Quality video.

    This is a man is awesome, you got a new subscriber.

  7. Whiskka December 14, 2019 at 12:33 am - Reply

    how do you make a local variable a global variable in an IF statement?
    For example:
    If num == 6:
    x = y
    i want x to be a global variable for y if this statement is true

  8. Harsh raj December 14, 2019 at 12:33 am - Reply

    x = 0
    for i in range(3):
    x = i
    print(x)

    I want 2 to be printed here ( change x inside loop ). What to do ?

  9. Micheal Bee December 14, 2019 at 12:33 am - Reply

    I think you skipped the "global" keyword.

  10. Command prompt December 14, 2019 at 12:33 am - Reply

    i was experimenting with functions, and this is exactly what i was looking for, thanks a lot man

  11. Mr.Anderson December 14, 2019 at 12:33 am - Reply

    Very good video. Thank You!!!!!

  12. TheLurkingPanda December 14, 2019 at 12:33 am - Reply

    This is the perfect tutorial.

  13. Wizard 28082006 December 14, 2019 at 12:33 am - Reply

    Awesome video, It cleared out my many doubts. Thumbs up to Mr. Schafer. Keep up the good work. I wish I found you earlier when I was struggling to learn java but I hated Python because I couldn't find a good instructor like you, the instructors I found made this language look very hard but now I have found you, I am changed my ambition from becoming a java developer to a python developer. Love you, Corey.

  14. Aaditya Shah December 14, 2019 at 12:33 am - Reply

    hey, i just wanted to know if it's good code to write nested functions

  15. jaz monark December 14, 2019 at 12:33 am - Reply

    A peron who hit the dislike on your videsos is a neanderthal!

  16. jaz monark December 14, 2019 at 12:33 am - Reply

    People has tutorials….. But YOU are a real teacher who says the truth … The "shape of my heart" song is meant for you❤

  17. Tero Liikala December 14, 2019 at 12:33 am - Reply

    Amazing

  18. Paul Sih December 14, 2019 at 12:33 am - Reply

    14:23 Wish it can use { } to tell where the scope end.
    for example
    def outer():
    {
    x = 'outer x'

    def inner():
    {
    # x = 'inner x'
    print(x)
    }
    inner()
    print(x)
    }

  19. arun kumar December 14, 2019 at 12:33 am - Reply

    Which application u r used for python

  20. Gaurav Parashar December 14, 2019 at 12:33 am - Reply

    One more thing that would make your tutorials even more awesome is if you created some sample programming assignments to help us test the concepts that we learnt. I know that's a little too much to ask, but i think that would be wonderful and supremely helpful!

  21. Noman Abid December 14, 2019 at 12:33 am - Reply

    If you die, my career will die.

  22. DAni M December 14, 2019 at 12:33 am - Reply

    Corey Corey. We love you…….. Sorry I can't be member of your Patron for now because of my situation . But I promise I will do 100%

Leave A Comment

*