What is Scope in Python??
Vložit
- čas přidán 20. 03. 2023
- ⭐ Join my Patreon: / b001io
💬 Discord: / discord
🐦 Follow me on Twitter: / b001io
🔗 More links: linktr.ee/b001io
Background Music:
Gentle Lo-Fi Vlog Background Music | Cookies by Alex-Productions | onsound.eu/
Music promoted by www.free-stock-music.com
Creative Commons / Attribution 3.0 Unported License (CC BY 3.0)
creativecommons.org/licenses/... - Věda a technologie
Would have been good if you covered how scopes relate to loop bodies and if/else blocks, because it's not intuitive in python. For example, in every language which I'm familiar with besides python, a variable declared inside an if block is scoped to that block, and not accessible outside it. This is not the case in python.
these are VERY important things to learn, love the video and thanks for the clear + concise explanation!!
Wow this was awesome. Your channel is criminally underrated!
Love the videos. Concise yet full of information for new learners. Thanks.
Thank you for this video!
ur channel deserves more subs. Your content is amazing👍
Thanks man what a smooth explanation
Great stuff! Good to learn more about how Python "thinks" lol
Amazing Explanation , Thank you.
Your explanation of coding is truly ingenious. Suddenly, all those encrypted coding lines aren't that confusing anymore.
Beautifully taught!
2:34 while this is indeed obvious for anyone experienced with interpreted languages, it could be confusing for begginers coming from compiled languages, like C, which is quite commonly used in intro to programming classes, so it's worth to point it out.
I think you meant it's obvious for anyone experienced with compiled languages.
Some interpreted languages like JavaScript, awk, various BASIC dialects, and some flavors of shell script do not require variables to be defined before they are used.
I've never encountered a compiled language that allows you to use a variable without first defining it.
Man your video really helps. I couldn't understand the explanation on the official doc. Tyvm!
Great explanation of scope! You made it very easy to understand!
Best scope explanation ever, many thanks to you
Lovely video!
I like the way you explain things. Subscribe button smashed.
thanks man
Thank you for this great explaination!
Great explanation with examples ! Bravo
I would love to see kind a approach about OOP. Because sometimes there is an overkill to use it. But otherwise its good practice i think. What do you think or whats your approach. I tend to do less OOP cause often "one time" use of my scripts
Thanks, you answered my awaited long question.
very good explanation... very helpful
Great stuff
really informative
😍😍😍😍😍
bro literally did a few vids and already 82k subs, gut 4 u
Thnak you broo!!!
Bro you are insane, can you do a python course , by the way where do you get all this knowledge
Ty
great explanation
Good video
Probably one of the most important videos to watch if someone is new to python
1:37 by first-indentation he means that variable was defined outside of classes and functions. This part confused me too because I though that he meant 1st line.
Could you do a video which does a clear breakdown of classes?
I didn't participate in the poll, but from very recent experience I knew it would be an error as soon as I looked at it. A couple weeks ago I was working on a script where I wanted to redefine a global variable, but I didn't use global inside the function. What's even weirder is I tried doing it with 2 different variables, and only the second one gave an error. The first variable was redefined, and printed what I was expecting, but then I got the error when trying to print the second variable. This may be a bug in Python 3.10 that I need to further explore.
the music is fire it got me dancing. and it remind me of minecraft
Can you share what color theme you are using?
I knew of "global", but I didn't know about "nonlocal"
I learned this on practice, i wish i viewed this video before
What if you want to reference a local variable two scopes out, how would you do that? Nonlocal only references the previous scope and global only references the global scope.
def outer():
x = 1
def inner():
# x = 2
def func():
nonlocal x # refers to x=1
If you uncomment the x=2 line, you'd be referencing that x variable instead, and you'd be forced to rename one of those two x variables to be able to reference both of them.
The nonlocal keyword is kind of a hack because Python is designed in a way that it prefers creating shadowed variables instead of unexpectedly modifying variables from outside scopes.
Unfortunately, that means you encounter variable shadowing issues more frequently if you don't name things uniquely enough, along with the surprising error that is the answer to the poll question.
@@epsi so the only way is basically to rename them or remove them
@@montagetm
Yes, but that's true for any other language as well.
Variable shadowing: just don't do it.
what is your theme vscode ?
i though python was interpreded so it reads code line by line, shouldn't it print x and then make a local variable x instead of giving error
2:30 not obvious if you coming from a compiled language.
What is the name of the theme?
Can you do a video on 360 no scope in Python next?
There is no compile time in python, it is called interpret.
What font is that? And what theme?
SynthWave '84
9:17 This whole thing is a disgusting mess
bru put the music louder pls
dont use global guys.
This language is conflicting coming from C++. We were taught that this kind of programming was for those ignorant BASIC programmers of the 70s. 😳
Js scope is better
Too basic for me