Python Tutorial: Variable Scope - Understanding the LEGB rule and global/nonlocal statements @coreyms
Python Tutorial: Variable Scope - Understanding the LEGB rule and global/nonlocal statements  @coreyms
Uploaded December 2016 | Updated November 2026, 1 hour ago
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:
github.com/CoreyMSchafer/code_snippets/tree/master/Scope


✅ Support My Channel Through Patreon:
patreon.com/coreyms

✅ Become a Channel Member:
youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join

✅ One-Time Contribution Through PayPal:
goo.gl/649HFY

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

✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1

✅ Equipment I Use and Books I Recommend:
amazon.com/shop/coreyschafer

▶️ You Can Find Me On:
My Website - coreyms.com
My Second Channel - youtube.com/c/coreymschafer
Facebook - facebook.com/CoreyMSchafer
Twitter - twitter.com/CoreyMSchafer
Instagram - instagram.com/coreymschafer

#Python
Python Tutorial: Variable Scope - Understanding the LEGB rule and global/nonlocal statementsLinux/Mac Tutorial: Cron Jobs - How to Schedule Commands with crontabPython Flask Tutorial: Full-Featured Web App Part 2 - TemplatesVirtualBox: How to Use SnapshotsPython Tutorial: Itertools Module - Iterator Functions for Efficient LoopingPython Tutorial: Real World Example - Using Patreon API and Pillow to Automate Image CreationPython OOP Tutorial 4: Inheritance - Creating SubclassesPython Tutorial: Type Hints - From Basic Annotations to Advanced GenericsHow to Create a Network of Machines in VirtualBox with SSH AccessHomebrew Tutorial: Simplify Software Installation on Mac Using This Package ManagerPython FastAPI Tutorial (Part 17): Testing the API - Pytest, Fixtures, and Mocking External ServicesPython Django Tutorial: Deploying Your Application (Option #1) - Deploy to a Linux Server
Corey Schafer |

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

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER