Тёмный

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

Corey Schafer
Подписаться 1,4 млн
Просмотров 361 тыс.
50% 1

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/Cor...
✅ 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...
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Опубликовано:

 

16 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 362   
@julianmahler2388
@julianmahler2388 2 года назад
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
@saitaro
@saitaro 7 лет назад
Corey. Man. It's so great that you exist. Thank you.
@User-nq9ee
@User-nq9ee 6 лет назад
:D
@dequationblog
@dequationblog 5 лет назад
Ex Corey Schafer Tutorials nulla salus
@shazkingdom1702
@shazkingdom1702 5 лет назад
You are right!
@plazmikpond
@plazmikpond 4 года назад
:D
@alitajvidi5610
@alitajvidi5610 3 года назад
Can't agree more with this comment
@kobas8361
@kobas8361 5 лет назад
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
@DisgruntledVet 4 года назад
Definitely!
@falsedragon33
@falsedragon33 4 года назад
RIP
@quant.481
@quant.481 4 года назад
RIP
@plazmikpond
@plazmikpond 4 года назад
RIP
@kristiyanivanov7414
@kristiyanivanov7414 4 года назад
RIP
@ousmanetall1286
@ousmanetall1286 6 месяцев назад
I have never seen a better explain tutorial of LEGB, thank corey, wish you all the best!
@gideonfelt2819
@gideonfelt2819 7 лет назад
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
@coreyms 7 лет назад
Awesome. Glad to hear that!
@coreyms
@coreyms 7 лет назад
Oh wow. Thanks a lot. I really appreciate that.
@sanjaykumarchoudhury4522
@sanjaykumarchoudhury4522 4 года назад
Agree, he is great teacher..Best in world
@pixelatedreverie
@pixelatedreverie 2 года назад
Plot twist.. It was Google along who knew both what you thought and @Corey thought.
@DevaKalidass
@DevaKalidass Год назад
😂
@PedroHenrique-ps8kj
@PedroHenrique-ps8kj 2 года назад
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 !!
@cemalcakir
@cemalcakir 3 года назад
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!
@janick9945
@janick9945 5 лет назад
this video has been an awakening. I don't understand why anyone has come up with such an eloquent explanation as yours before.
@andresvodopivec5950
@andresvodopivec5950 5 лет назад
Corey I have never seen anyone to explain this basic and very important information. Thanks.
@nitkap441
@nitkap441 4 года назад
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.
@liesdamnlies3372
@liesdamnlies3372 7 лет назад
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.
@jazmonark3309
@jazmonark3309 5 лет назад
People has tutorials..... But YOU are a real teacher who says the truth ... The "shape of my heart" song is meant for you❤
@hussainmadar4
@hussainmadar4 4 года назад
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.
@wizard-28
@wizard-28 5 лет назад
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.
@the_xibalba
@the_xibalba 3 года назад
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!
@jonathanessien4360
@jonathanessien4360 4 месяца назад
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 🙏
@thevgancheetah
@thevgancheetah 4 года назад
Your teaching skills are truly amazing! I understood everything crystal clear! Thank you so much!
@davidalexander829
@davidalexander829 6 лет назад
Masterful clarity in simple conversational language. What a relief
@Airless_Grind
@Airless_Grind 4 года назад
Every single thing i look up during my python course always leads me to your channel, you're an absolute blessing.
@caydanphoenix9067
@caydanphoenix9067 3 года назад
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!!
@dkq986
@dkq986 4 года назад
Clarity in the way you speak is amazing!!
@rockingraphsody3019
@rockingraphsody3019 6 лет назад
the only professional content creator of python in youtube.. you rock corey !!
@appletreegfx806
@appletreegfx806 Год назад
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.
@NaderTaghinia
@NaderTaghinia 5 лет назад
Every second of your videos is highly worthwhile Mr.Schafer...Thank you so much and God bless you!
@davorm4634
@davorm4634 7 лет назад
I`ve just start to learn Python and find yours tutorials best here, seriously. ( I look many of them ). Thanks a lot man !
@DisgruntledVet
@DisgruntledVet 4 года назад
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!
@aijaz4441
@aijaz4441 9 месяцев назад
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.
@peek-a-boosurprisetoysandf5794
You are one of the best Python instructors on RU-vid! Your tutorials explain complicated concepts in a beautifully succinct and clear manner. Just became a patron! 👍👍👍Thanks for sharing your knowledge with us!
@coreyms
@coreyms 7 лет назад
Thank you! That really helps a lot!
@isaacfinch2141
@isaacfinch2141 2 года назад
5 years later, you're still one of the best!
@Ninja-iq2xt
@Ninja-iq2xt 7 лет назад
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!!!
@ArchitecturalAesthetics2046
@ArchitecturalAesthetics2046 5 лет назад
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.
@newsjuice7404
@newsjuice7404 2 года назад
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
@yingbowang3068
@yingbowang3068 2 года назад
that nonlocal is amazing..Thank you Mr Schafer for those excellent tutorials
@soumyazyx
@soumyazyx 4 года назад
Thank you Corey for your time and effort. Keep spreading the knowledge.
@0x656e
@0x656e 4 года назад
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
@coreyms 4 года назад
Thanks!
@randomsamurai8759
@randomsamurai8759 3 года назад
Just an organic comment to show some appreciation. Best python tutorials on the internet!
@SpreadHumanity118
@SpreadHumanity118 5 лет назад
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.
@manharts
@manharts 6 лет назад
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.
@supersaiyan0x016
@supersaiyan0x016 4 года назад
Definitely worth it.. You explain far better than my college teacher ...
@exili
@exili 6 лет назад
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!
@sueholder703
@sueholder703 5 лет назад
This was an excellent way to present this confusing topic - thanks!!
@vinces.9990
@vinces.9990 4 года назад
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.
@anuragkadam7935
@anuragkadam7935 2 года назад
Corey's python videos are "global" treasure
@tanuj05
@tanuj05 2 месяца назад
Awesome video Corey , your videos are awesome !
@danielm3977
@danielm3977 5 лет назад
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%
@coreyms
@coreyms 5 лет назад
Thanks!
@anguspearson1
@anguspearson1 5 лет назад
So clearly explained. Thank you for an excellent tutorial!
@nazzak2093
@nazzak2093 Год назад
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.
@Mrjarnould
@Mrjarnould 7 лет назад
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.
@pranav6610
@pranav6610 4 года назад
It's awesome that your alive thanks for this
@commandprompt7171
@commandprompt7171 5 лет назад
i was experimenting with functions, and this is exactly what i was looking for, thanks a lot man
@ricardo.fontanelli
@ricardo.fontanelli 4 года назад
Your videos are great for programmers moving from other languages to python, thank you
@brukselkowyben7628
@brukselkowyben7628 6 лет назад
Your tutorials are great, I really appreciate your effort.
@ajeet3259
@ajeet3259 5 лет назад
Thank you for such crystal clear explanation.
@kinkdaka1
@kinkdaka1 3 года назад
A perfect explanation!
@raibahati
@raibahati 3 года назад
I am gonna contribute because i have learned so much thanks to you!
@sharonsnail2954
@sharonsnail2954 2 года назад
Excellent!! Best tutorial I've ever seen on this topic 👍👍👍👍👍
@akira_asahi
@akira_asahi 2 года назад
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@shihabkhan3218
@shihabkhan3218 3 года назад
I open Corey's videos, hit like, and then start watching :P
@sak8485
@sak8485 7 лет назад
this tutorial series is awesome, Thank you so much man :)
@ashenisuranga2915
@ashenisuranga2915 Год назад
you sounds clearer than my teach bro. nice work
@nicolasgaritagoitia5536
@nicolasgaritagoitia5536 3 года назад
This is the best, thank you very much. The explanations in the python official documentation is a lot harder to understand
@ardcapture3D
@ardcapture3D Год назад
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
@heshankumarasinghe3159
@heshankumarasinghe3159 4 года назад
Thank you for this video..... This video has been really helpful.....
@davey7205
@davey7205 Год назад
Just an outstanding explanation. Cheers for Corey. Really grateful for your content.
@SoroushAzizzadeh
@SoroushAzizzadeh 4 года назад
Great content Corey, Keep up the good work :)
@GraciaEdhyta
@GraciaEdhyta Год назад
very very clear and complete explanation, thank you so much!!!
@MohSo14
@MohSo14 11 месяцев назад
How great explanation on this topic. Great job!
@ManuelShelton
@ManuelShelton 6 лет назад
Very clear structured lession about LEGB.
@zehuawang5765
@zehuawang5765 4 года назад
Very clear and easy understanding, thanks !
@angelak3060
@angelak3060 4 года назад
Really great tutorial!
@vijay270886
@vijay270886 Год назад
Thanks a lot Corey Schafer.
@hubertcombomarketing2693
@hubertcombomarketing2693 4 года назад
Great tutorial. Thank you.
@Play_Streams
@Play_Streams 7 месяцев назад
These lessons are really valuable. Would you consider adding chapters to the videos to help locate the sections?
@bostevens236
@bostevens236 4 года назад
Love your videos. Thank you so much!
@Roule_n_Scratche
@Roule_n_Scratche 2 года назад
Thanks for a easy explanation on the topic
@gianmarcoria2468
@gianmarcoria2468 3 года назад
Still best tutorial online, in 2020
@muhammadkarim4231
@muhammadkarim4231 3 года назад
Loved the way you explained the scope so well
@ajaysharma12799
@ajaysharma12799 5 лет назад
Man god has send you from heaven for helping us to learn python
@sonumpsah1
@sonumpsah1 6 лет назад
@corey, What a great video!!! Just adding support for python 2.X The nonlocal keyword does not exist in python 2.X, so here is the way around. (choose any one from those two) def outer(): x= {'x': 'outer x'} def inner(): x['x']= 'inner x' print x['x'] outer() print x['x'] def outer(): outer.x= 'outer x' def inner(): outer.x= 'inner x' print outer.x outer() print outer.x Output: inner x inner x
@tymothylim6550
@tymothylim6550 3 года назад
Thank you very much for this video! It was very interesting and I didn't know we could use "global" and "nonlocal" :)
@sanjayshr1921
@sanjayshr1921 7 лет назад
awesome :) looking forward more videos on Python . thank you
@saidhussainmusawi
@saidhussainmusawi 2 года назад
Thanks a lot Corey, you explained it in a best possible way
@radhakrishnavarukuti1601
@radhakrishnavarukuti1601 5 лет назад
Couldn't go without liking the video !!
@RameezRaja-qc9fi
@RameezRaja-qc9fi Год назад
Thank you so much Corey! This video really helped me to understand this concept completely now!
@rawankhaled8394
@rawankhaled8394 6 лет назад
You're really awesome. thank you so much, and please keep on doing more videos
@dubanaveen5678
@dubanaveen5678 4 года назад
Outstanding!!
@pranavpawar1894
@pranavpawar1894 4 года назад
Thanks Corey for uploading such a wonderful playlist
@markkelton5220
@markkelton5220 4 года назад
Great videos Corey. Hi from Australia. ;)
@rockershocker007
@rockershocker007 3 года назад
Thanks a lot. You explained it so beautifully.
@thelurkingpanda3605
@thelurkingpanda3605 5 лет назад
This is the perfect tutorial.
@abinandankumar5283
@abinandankumar5283 5 лет назад
Great, You just made it simple. Thanks
@mlittleprogramming780
@mlittleprogramming780 4 года назад
Great Video!
@semih3704
@semih3704 5 лет назад
Awesome tutorial!!!
@mr.anderson5393
@mr.anderson5393 5 лет назад
Very good video. Thank You!!!!!
@vikashgauravvkg
@vikashgauravvkg 4 года назад
wow, amazing explanation, I was quite confused because javascript works very different.
@rohitsoni2439
@rohitsoni2439 6 лет назад
You are God for mine, here in India Teachers resembles Gods. Thank you so much Schafer :)
@pawanbhatt314
@pawanbhatt314 4 года назад
edit* > not teachers but good teachers. :)
@hassaniqbal7934
@hassaniqbal7934 4 года назад
What about holy cow?
@udaykhanna1
@udaykhanna1 2 года назад
@@hassaniqbal7934 What about holy camel and pigs🐫?
@senthilnathans5663
@senthilnathans5663 2 года назад
Really useful video @corey schafer
@ramveerla
@ramveerla 2 года назад
Excellent! Straight and to the point
@chenxingliu2675
@chenxingliu2675 7 лет назад
You tutorials are the best!!!
@chaitanyayeturi1312
@chaitanyayeturi1312 3 года назад
First of all, your teaching style is good, and anyone grabs ur teachings easily, and thanks for teaching us. you are the best tutor I have ever come up with in python language. can u suggest any python language book, which is best to go through other than your channel? Moreover, I am a beginner to python language I thoroughly enjoyed ur videos, if u can suggest me best python book to ur sensibility and I guess it suits me and it helps me to learn further (I like physical like books). In case if u written any books related to this language can u suggest one (or) your favorite book, please......................................
@manivannan33
@manivannan33 2 года назад
Excellent explanation!
Далее
Python Tutorial: Sorting Lists, Tuples, and Objects
12:07
Mini bag sealer
00:58
Просмотров 4,2 млн
Vibes in Ney York🗽❤️! #shorts
00:26
Просмотров 22 млн
15 Python Libraries You Should Know About
14:54
Просмотров 388 тыс.
Premature Optimization
12:39
Просмотров 806 тыс.
25 nooby Python habits you need to ditch
9:12
Просмотров 1,8 млн
What is Scope in Python??
10:25
Просмотров 49 тыс.
The Flaws of Inheritance
10:01
Просмотров 941 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 805 тыс.
Python 101: Learn the 5 Must-Know Concepts
20:00
Просмотров 1,2 млн
Modern Python logging
21:32
Просмотров 185 тыс.