Python Tutorial: Variable Scope - Understanding the LEGB rule and global/nonlocal statements
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...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python
Пікірлер: 360
I think many people don't even realize how well-thought-out and well-prepared your videos are. Your step by step explanation skills are unsurpassable
Corey. Man. It's so great that you exist. Thank you.
@User-nq9ee
6 жыл бұрын
:D
@dequationblog
5 жыл бұрын
Ex Corey Schafer Tutorials nulla salus
@shazkingdom1702
4 жыл бұрын
You are right!
@plazmikpond
4 жыл бұрын
:D
@alitajvidi5610
3 жыл бұрын
Can't agree more with this comment
Mate, I'm being forced to watch some random Python tutorial at my Python Internship and it's a real pain in the ass to do so once one knows your channel. I just realized that theese might honestly be the best tutorials in the web...
@DisgruntledVet
4 жыл бұрын
Definitely!
@falsedragon33
4 жыл бұрын
RIP
@quant.481
4 жыл бұрын
RIP
@plazmikpond
4 жыл бұрын
RIP
@kristiyanivanov7414
4 жыл бұрын
RIP
I have never seen a better explain tutorial of LEGB, thank corey, wish you all the best!
Just wanted to write this after what you said about global variables (not to overuse them). You are not just teaching stuff, also giving great informations and insights about programming. That's a gem!
Amazing work, we are really living a great era of transformation where such high level of information is widely available and accessible , what a blessing !!
Man you are a heaven send! I literally was thinking I need to study scope more since being new to python and programming in general I was having lots of problems, and then Google notifies me about this video being released 10 mins latter, wow its just perfect, absolutely perfect, it even covered everything I was thinking about. Thank You so much.
@coreyms
7 жыл бұрын
Awesome. Glad to hear that!
@coreyms
7 жыл бұрын
Oh wow. Thanks a lot. I really appreciate that.
@sanjaykumarchoudhury4522
4 жыл бұрын
Agree, he is great teacher..Best in world
@pixelatedreverie
2 жыл бұрын
Plot twist.. It was Google along who knew both what you thought and @Corey thought.
@DevaKalidass
Жыл бұрын
😂
this video has been an awakening. I don't understand why anyone has come up with such an eloquent explanation as yours before.
Again a very crisp video. I learnt programming in 1994 on IBM mainframe and did work on Cobol/DB2/CICS etc. but soon moved into managerial role. One of my biggest problems with lot of videos is that they all spend lot of time on useless explanations... I need someone like you who is short and crip and to the point(because I know programming as such..but need specifics)... I get every minute worth in your videos with no waste of time.
People has tutorials..... But YOU are a real teacher who says the truth ... The "shape of my heart" song is meant for you❤
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.
I`ve just start to learn Python and find yours tutorials best here, seriously. ( I look many of them ). Thanks a lot man !
I'm glad you added the part about "Look, that's how it works, but you shouldn't overuse it." Globals are dangerous beasts. Certain (now deceased) Toyota owners learned that the hard way. It's an easy thing to have overlooked, but very important.
I has been frantically searching for a proper tutorial on sending emails using Python. I was literally pulling my hair off by reading and implementing solutions from Stack Overflow which introduced some other bus in my project. I accidentally stumbled upon your channel and boy am I glad that I did. Thank you so much for doing this mate, you are making a difference in the lives of other people, I hope you are doing well in these times. Thank you once again!
Hey Corey, you cant imagine how helpful this video turned out to me, i was stuck in one project for a long time, but you just made my day, my solution was right into the variable scope, Thanks a lot!!!
Your teaching skills are truly amazing! I understood everything crystal clear! Thank you so much!
Corey I have never seen anyone to explain this basic and very important information. Thanks.
Every single thing i look up during my python course always leads me to your channel, you're an absolute blessing.
Masterful clarity in simple conversational language. What a relief
1st year compSci student here and this helped in more ways than you can imagine. started coding in delphi so there was no need for Enclosing or Builtins and didnt know why my global values were not changing but thank God for you. Much appreciated 🙏
Wonderful work @Corey Schafer. I have seen so many tutorials, but your tutorials are the best. Many thanks to @Krish naik for suggesting me your tutorials.
My MAN!!! Thank you so much! First video that explained it where I could understand it. I tried a couple other channels and couldn't get it. I was so confused until I watched this video. I'm new to Python and this helped out a lot. Thank you so much!
Every second of your videos is highly worthwhile Mr.Schafer...Thank you so much and God bless you!
the only professional content creator of python in youtube.. you rock corey !!
corey your videos are so compelling ....before going to interview i refer them ..great work,keep going .you are helping a lots of tech lovers to learn.
great tutorial. answered so many of my questions. I've been teaching myself python by reading head first python but the author didn't explain the variable scopes, which caused me a lot of confusions when I was writing custom functions.
Clarity in the way you speak is amazing!!
Thank you Corey for your time and effort. Keep spreading the knowledge.
Thank You so much, for all the time you put in to your videos! If ever you do a weeklong coding-bootcamp class I'm there!
This was an excellent way to present this confusing topic - thanks!!
So clearly explained. Thank you for an excellent tutorial!
i was experimenting with functions, and this is exactly what i was looking for, thanks a lot man
Always a good day when I see you've released a new video! I'm looking forward to seeing a tutorial on Pandas and Sublime Text Setup for Python Development. All the best, Jacob.
Your tutorials are great, I really appreciate your effort.
I totally agree on Julian M's comments. This lecture is very well-planned and highly organized. I came to Corey's video after several stops that I wasn't satisfied much. Happy to find Corey S videos.
if i had access to a million mail id's, i would have subscribed this channel with each of them...this is in my opinion #1 channel for python..this video cleared every doubt i had in this topic..tysm dude!!
You are the best teacher to explain the core concepts so neatly. I always check your channel for any content that I need help with. Thanks. God Bless you.
You are an outstanding teacher! Although I get most of this content now, it took me a long time to get this concept in my head. Wish I'd seen this demonstration around 25 years ago. I'd say even if the rules may be slightly different in other languages, the logic still applies.
that nonlocal is amazing..Thank you Mr Schafer for those excellent tutorials
this tutorial series is awesome, Thank you so much man :)
I learned python from you including frameworks like Flask & Django plus pandas, Numpy, mayplotlib, SQL also & I guess I am job ready now & the very first thing I ll do is to support this channel inshallah
Your videos are great for programmers moving from other languages to python, thank you
You are one of the best Python instructors on KZread! Your tutorials explain complicated concepts in a beautifully succinct and clear manner. Just became a patron! 👍👍👍Thanks for sharing your knowledge with us!
@coreyms
7 жыл бұрын
Thank you! That really helps a lot!
@isaacfinch2141
Жыл бұрын
5 years later, you're still one of the best!
Just an organic comment to show some appreciation. Best python tutorials on the internet!
Awesome video Corey , your videos are awesome !
Thank you for such crystal clear explanation.
You tutorials are the best!!!
I go ahead and like your videos before I even finish watching. I already know from previous videos that it will be what i'm looking for.
Very clear structured lession about LEGB.
Definitely worth it.. You explain far better than my college teacher ...
Thanks Corey for uploading such a wonderful playlist
Thanks a lot Corey Schafer.
Thank you so much Corey! This video really helped me to understand this concept completely now!
awesome :) looking forward more videos on Python . thank you
Loved the way you explained the scope so well
Very clear and easy understanding, thanks !
Just an outstanding explanation. Cheers for Corey. Really grateful for your content.
It's awesome that your alive thanks for this
Really great tutorial!
Great Video and very informative. Thank you so very much for posting.
Thank you for this great explanation, I never heard of LEGB and I never noticed or had to use global/nonlocal keywords before, probably because I code in C++ style where global variables are, kind of, forbidden. Thank you again for the good explanation. Now I know.
Thanks for a easy explanation on the topic
Excellent! Straight and to the point
A perfect explanation!
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
I am gonna contribute because i have learned so much thanks to you!
Great content Corey, Keep up the good work :)
Great tutorial. Thank you.
Thanks a lot Corey, you explained it in a best possible way
very very clear and complete explanation, thank you so much!!!
Great, You just made it simple. Thanks
Outstanding!!
Love your videos. Thank you so much!
Corey's python videos are "global" treasure
This is the best, thank you very much. The explanations in the python official documentation is a lot harder to understand
You're really awesome. thank you so much, and please keep on doing more videos
How great explanation on this topic. Great job!
Awesome tutorial!!!
hey Corey! if you reading this I hope you get all the happiness in this world because you deserve them thank you so much for these beautiful and great tutorials you're wonderful
@coreyms
4 жыл бұрын
Thanks!
Too good. The explanation of these concepts
This is the perfect tutorial.
Thank you very much for this video! It was very interesting and I didn't know we could use "global" and "nonlocal" :)
Perfect explanation. Well done!
Excellent!! Best tutorial I've ever seen on this topic 👍👍👍👍👍
Excellent explanation!
Beautifully explained!!!
Wow, that was excellent!! Thanks!!
Well-explained!
Thanks a lot! A very informative and clear explanation!
Couldn't go without liking the video !!
That was a thorough explanation, I grok scope now thanks!
Thank you for explaining it very well. i finally understood it
Really helpful - thanks!
Thanks a lot. You explained it so beautifully.
Corey great tutorial as always. The scope of lists and dictionaries seem to behave differently in this situation -would love to have one of your vids going into that. Many thanks Adrian
high quality tutorial, thanks.
Thank you for this video..... This video has been really helpful.....
really good tutorial! thanks
Easily understood, thank you.
simply amazing video