Dude, it's incredible how simple this concept is when it's explained well. So many other resources had my head spinning about it, but just one 8 minute KZbin video later, and I'm like "oh yeah well obviously."
@shaheenelt3 жыл бұрын
p Ppp
@Codeandventure3 жыл бұрын
shoot yeah Sam I am.
@tanchwa37403 жыл бұрын
same boat here I was like what the hell is a __main__ and why should I even care lol. But this makes so much sense. I especially understand someone else's stack exchange comment now about how this is really important for global variables.
@buddhahead87343 жыл бұрын
I'm glad this is where I looked first. It looked intimidating at first, but he made it make sense. Seems like a really intuitive feature.
@ronakpatel90232 жыл бұрын
You spoke my mind man….
@kogcyc5 жыл бұрын
Hi, Corey. If you ever wonder if you're making a difference in the world, then let me assure you that you are. Your videos make learning and using Python possible for those who watch them. Beautiful work. Thank you very much.
@coreyms5 жыл бұрын
Thanks!
@gonzalotoloza6700 Жыл бұрын
@@coreymsyeah you helped us so much, thank u
@dc32953 ай бұрын
yeah corey just released so much mental steam in the beginning python world....
@tyroneslothdrop91559 жыл бұрын
Subscribed: That was by far the best explanation I've found on KZbin regarding this topic. I hope you continue to make videos.
@AhmedBalfaqih9 жыл бұрын
I agree with you. I subscribed based on this video only.
@Kevin-iu4kj9 жыл бұрын
no. this shit makes no sense
@codestorywithMIK7 жыл бұрын
Tyrone Slothdrop I totally agree
@purpleice23437 жыл бұрын
Kevin, of course it doesn't make sense when you're braindead xD
@adityarprasanna7 жыл бұрын
Came to the comment section to say the same thing and I see I was beat to it.
@blmcmcn5 жыл бұрын
Short answer: this set up gives you the option to run (or not run) a chunk of code when imported from another python file
@Dorumin4 жыл бұрын
I got that from the first 20 seconds, it's quite a simple concept for me and I thought up a lot of usecases. Pretty interesting, I don't think I'll watch the rest of the video
@pulpil104 жыл бұрын
@@Dorumin you are so smart
@Dorumin4 жыл бұрын
@@pulpil10 Yeah, looking back on this comment it did seem pretty pompous lol, but it really was pretty familiar enough for me to grok like that An example being a chess program that either runs on the command line if you run it directly or offers an API if imported
@ChrisT-ib1zh4 жыл бұрын
@@pulpil10 and you are right
@isMeStranger4 жыл бұрын
@@Dorumin he explained nothing in the first 20 secs. Does patting yourself on the back make you feel any better?
@rukhan89004 жыл бұрын
I hope you know that even 6 years after posting your content is still helping beginners like me understand python better than anything else on the internet can! Thank you for your work, it's great! :)
@kellzbaker9 ай бұрын
9 years baby
@nigthfall3454 ай бұрын
hows your coding journey now?
@qbaloch2 ай бұрын
I gone through dozens of explanations but never understood the purpose of _name_ until I found your video... Thanks very much.
@vavilon71094 жыл бұрын
I thought that geneticists are terrible at naming things but coders have their share of confusing nomenclature. Despite that, I got it because of this video! Thanks Corey!
@zsszeli2 жыл бұрын
Man, this is the first video where I actually get what this means. You are the GOAT, my friend.
@layer4down5 жыл бұрын
The absolute clear and concise explanation I've seen on this in 5 years off and on of playing and working with Python. Well done!
@AliColak2 жыл бұрын
THIS MAKES SO MUCH SENSE. I spent an hour and a half today rewatching the video i learned it from and trying to get a grasp on it. Makes a lotta sense when you explain and show it the way you do. It's sort of like a validation prompt to see which file is being run to avoid duplicates etc.
@ashishdeora85224 жыл бұрын
It's hard to believe that such a complicated concept can be explained like this. Cheers Cory, the great!
@notanenglishperson98653 жыл бұрын
It's not that complicated, it's just terribly explained by others
@anindam91794 жыл бұрын
okay, this person is so nice that he repeated the same thing without sounding repeatative at all. anyway, coming to the point, I think for average,slow,diverted students the video needs to be seen twice or whatever, there's got to be some kind of repeatation; but for focused students he's a great teacher
@supermanish7 жыл бұрын
Haven't encountered an explanation as good as this. Thank you! The world needs teachers like you.
@crimepunishment53722 жыл бұрын
Corey, Man, you are an asset to humanity indeed, keep the good work.
@garydunken79347 жыл бұрын
I considered "if __name__ == '__main__'' as some magical conditional check that triggered the main function for me, until I watched this video today. It's clear now. Your explanation was so clear and simple it made so much sense. Thanks.
@yogiblak78192 жыл бұрын
You are quite literally the BEST explainer in the world! You could take any concept and get the most mentally incapable person to understand it. Great job!
@jenniferf.83874 жыл бұрын
New to Python, I'm a C# developer, this video was exactly what I needed... just had to find the right one so it would click. THANK YOU!
@adityapradhan8474 Жыл бұрын
I was terrified by this concept. But it was so simple. Thank you so much. People don't know how to teach, but you surely do...
@CuongNguyen-gu9fl Жыл бұрын
If you want understand Python more clearly, check the video "What does it take to be an expert in Python" by PyData. It will give you an overview of how Python, specifically the "underscore" methods, works.
@humanOSx6 жыл бұрын
man you are awesome, I started with the first video of Flask series and now I come here for understand the ifmain conditional. thanks for your youtube channel, it will be for very much help, I am a new subscriber, like in all your videos. Greetings from México.
@gambomaster4 жыл бұрын
One of the best Python instructor on KZbin. 👍👍👍
@lardosian6 жыл бұрын
Such a joy listening to your tutorials. The instructor in my paid course just keeps stuttering and mumbling to the point where I lose the will to live. You are a life saver, easily in the top 3 instructors online.
@coreyms6 жыл бұрын
Thanks! I stutter and mumble a lot as well, but I edit all of that out because I don't want to waste the viewers time. Glad you enjoy the videos!
@Sir-Ahmad-Khan5 жыл бұрын
This is the best tutorial so far. This thing is kinda tricky one. Sometimes i understand it but when someone ask me to make them understand, i start thinking maybe i did not get the concept, i have to check again.
@JoeEvansSound8 жыл бұрын
Thank you very much - I have read and read on this subject but was getting totally confused. This video explains things so much better. Thank you very much. Your video is very explanatory and well done. :¬)
@coreyms8 жыл бұрын
Thanks. Glad to hear you found it useful!
@nikhilchigali7 жыл бұрын
I agree!!! this video clarified my doubts!!
@myblurryfaceromance51464 жыл бұрын
Tried to understand this from my lecturers for 3 weeks. Understood it from your channel after 6 minutes into the video. TYSM
@nigelmtb6 жыл бұрын
What everyone else said: best explanation available. Thank you very much.
@cass123452 жыл бұрын
I came here because I was confused by a Udemy course I'm doing - your explanation was fantastic and simple. Thank you.
@JRavenell6 жыл бұрын
This is the best explanation with EXAMPLES I've ever seen on this. This will help me tremendously. I salute you!
@Waterlmelon2 жыл бұрын
This is the best explanation for if __name__ == '__main__' that bothered me every time I saw it in a python code and tried to ignore it and escape from it. Thousand thanks!!
@codestorywithMIK7 жыл бұрын
You are the only one whose lecture cleared my concept of __main__ in python. i subscribed to your channel as soon as I understood the concept. thanks. keep uploading.
@seancampbell16827 ай бұрын
Man, I was having a tough time understanding this concept. Thank you so much for this excellent explanation!
@EV4UTube2 жыл бұрын
I have found a way of conceptualizing this line of code in a way that (for me) may be easier to understand ... Think of any single individual who is part of a family; we will call this person Xavier. Let's talk about the relative terms we use when relating Xavier to the rest of his family. His parents consider Xavier to be his SON. His sister considers Xavier to be her BROTHER. His second-tier relatives consider Xavier to be their COUSIN. His grandparents consider him to be their GRANDSON. Lastly, Xavier considers Xavier to be HIMSELF. Xavier is still the same person in each of these relative relationships, but the relative term we use for him is different depending on who we are relating to. So, when we write, "If __name__ == __main__" then we are effectively asking is: "If == HIMSELF" If that code evaluates to TRUE, then we know that the program is running on its own - it is referring to itself. == "HIMSELF" If, however, that code evaluates to FALSE, then we know that the program is running as a component of another program. That is, when you run the code "if __name__ == __main__" and it evaluates as FALSE, then it would be **metaphorically** equivalent to the return values being something like the following: == "SON" == "BROTHER" == "COUSIN" == "GRANDSON" In other words, Xavier is not operating as HIMSELF, he is operating in relation to some other entity (a subcomponent of another program).
@FloppyCuber1993 Жыл бұрын
this made me confused as hell at the beginning ;) But is a good explanation too.
@lvplvp Жыл бұрын
Wow thank you for the great explanation!!
@Mr.Jiggle Жыл бұрын
it is more like if relative pronoun is not son, brother, etc.. then this is not the main "xavier" it is someone else IMPORTED to this file "family", correct me if im wrong
@EV4UTube Жыл бұрын
@@Mr.Jiggle I dont see a problem with your analogy. However, I also dont see a difference. I feel like you identified a difference with no real distinction. If Xavier is your nephew, he's not your child (you've imported him to your family). But if your approach helps you capture the concept, then run with it.
@Mr.Jiggle Жыл бұрын
@@EV4UTube thanks, i was just making sure that i caught it right, i almost understand rn, thank you again
@abu51974 жыл бұрын
I've literally been searching for this for the past two years. So simple yet I haven't seen anyone explain it better!
@Baba-so6fh3 жыл бұрын
Finally it makes sense! Great video. So I understand now that the variable __name__ is different depending on whether the Python file is being run directly as a script or if it is imported somewhere else. If someone imports it, you can choose for the contents not to be run.
@pptx7044 жыл бұрын
I have read a lot of articles on this specific topic, but none of them could make me understand this "if __name__==__main__" thing. Thanks for making it simple and understandable. By far the best one I've come through!
@potterdkk43714 жыл бұрын
I stuck for DAYS on this, THANK YOU SO MUCH for explaining the topic really clearly.
@chilukanand Жыл бұрын
Feels so good when you get to decipher __name__ = '__main__'. For years it was a huge mystery and blindly went with the flow. Thanks for the clarity distinguished mate!
@alfredgarrett95897 жыл бұрын
I commend you on your teaching. I struggled with this concept for a long time, now it seems so simple.
@whateverbrian11 ай бұрын
Holy crap I’ve been looking for a good explanation of this for forever. After not understanding when I first started learning I just skipped past it and always ignored it every time I saw it. But today I decided I was going to sit down and understand it and you made it clear. Thank you.
@tahep39065 жыл бұрын
this seemingly complex topic can't be explained better that this, thanks a lot for clarifying it...
@BythanProductions4 жыл бұрын
I spent all morning finishing your OOP walkthrough videos and just ended with this. You, sir, are amazing.
@MrTigerstyle805 жыл бұрын
THE MOST cogent explanation of python import machinery available IMHO.
@prasadnaik60463 жыл бұрын
I have taken the python course for 300 $ in Bangalore , listened to the class but I have not understood the topic well and here I learned it better...Thank you so much sir...Keep spreading the knowledge and continue making more videos.........SUBSCRIBED
@dwainetrain6 жыл бұрын
Your clarity is a godsend! Thank you for the instruction Schafer Sensei!
@daniel-u7t9q11 ай бұрын
8 years later and it's still useful! Thank you so much for the amazing video :)!
@4abdoulaye5 жыл бұрын
Clearest one I ever found and reference my friends.
@nitishbansal68783 жыл бұрын
Finally understood this after 2 years of starting programming!!
@Skypriv5 жыл бұрын
You rock. I'm so lucky, I looked down out of confusion while watching a tutorial because this was used (but I had no clue what it was).. my eyes just happened to see this video suggested, noice
@abdelhaqfaouzi5 жыл бұрын
I'm learning Python on my own and haven't reached the underscored 'thingies', but just watching this video, I understood the whole concept!! Thumbs up!! thx
@jayw.11396 жыл бұрын
Sir, you will live 10,000 years!! Thank you for this informative video. Straight and to the point to which I could easily comprehend.
@shahulvkhameed4 жыл бұрын
No one in this planet can give this much simpler explanation.....hats off to Corey Schafer
@giorgionapoli857 жыл бұрын
"So, I really hope this video was useful..." Yes man... yes. Big YES. Damn it, thank you! And it's not the first time you englightened me.
@haiderhani19984 жыл бұрын
i've been roaming around for two days now. this is by far the best video i found. just subscribed!
@vinhtranphuc7155 жыл бұрын
Great! You're one of the greatest Python tutor on KZbin
@ansariataullah30644 жыл бұрын
It was very helpful ,I stuck here for 1 day. Your teaching is in very simple simple way easy to understand by any one.......
@LuisMan88 жыл бұрын
You say: "Thank for wacht it"... I say : Thank for teach me !!!!
@sourabhsaini9676 жыл бұрын
You r right
@nemplayer17766 жыл бұрын
NemCorrect: You say: "Thanks for watching" I say: "Thanks for teaching me!" Always on service.
@ycombinator7655 жыл бұрын
@@nemplayer1776 you did not get the joke!
@hanle25665 жыл бұрын
@@ycombinator765 what is the joke? mind to elaborate?
@copperymarrow15835 жыл бұрын
r/whooosh
@board_runner3 жыл бұрын
Cheers. Finally an explanation that made sense. How others have failed to explain _that_ is beyond my imagination.
@Sheriff.Movement4 жыл бұрын
Can't get better explanation than this🙏🏼
@heron22wading4 жыл бұрын
you can have waaaaaaaaay better explanations than this crap. He just wrote shit and didn’t bother to explain new stuff
@skull41104 жыл бұрын
@@heron22wading fuck off. Writing stuff is exactly what I needed.
@jparth15934 жыл бұрын
Agree
@AmitParam4 жыл бұрын
@@dr.rijjaayaz8160 ___
@AmitParam4 жыл бұрын
@@dr.rijjaayaz8160 sgs
@fafza15 жыл бұрын
Finally. I had seen that scary double underscore several times and couldn't figure out what it was all about. Thank you for the explanation.
@ducpham99915 жыл бұрын
After three years used python, finally, i know why they use it :)) thanks so much
@aatt32095 жыл бұрын
OMG, this is the first time I am getting the concept using __main__, thank you so much for being a great teach!
@nelsongg3475 жыл бұрын
THE best explanation on the subject. Thanks Corey!!
@Moh_ha4 жыл бұрын
I was really confused the first time I watched the video. now I got it!! thanks man
@zaqwsx284 жыл бұрын
KZbin recommendations can apparently read my mind. Thanks for covering this topic!
@alpstinger50833 жыл бұрын
The guy is a pure genius. Crystal clear explanation.
@sephkm74826 жыл бұрын
thos was the best and really honestly ever best explanation for this term I've been always trying to understand! Thanks so so much!!
@belacy874 жыл бұрын
Great video. I learned Python from a bootcamp which skipped these essential basics. Very helpful !
@afrankiuk785 жыл бұрын
Great explanation! I completed a graduate program in data science and none of the professors explained this as clearly.
@omergrn59854 жыл бұрын
There is no beetter explanation than this video bro Thnx from 5 years later !!!
@Sabre005 жыл бұрын
When I found this out at first I couldn't see the usefulness of it but I realized that I could test my modules separately and not have it called within my main program. Great explanation as always.
@abdulraaziq70554 жыл бұрын
This guy explains the best...answers all the questions that appears in the mind while watching...keep going
@1377sv6 жыл бұрын
brilliant yet concise explanation. ThankYou
@ericsteph4 жыл бұрын
Hats off! you exaplain it simply and clearly. I have always thought this main story was complicated but thanks to you, now I fully grasp it.
@bhaskartrivedi31143 жыл бұрын
2021: These are future-proof tutorials!
@joshuapeterson20843 жыл бұрын
EVERY SINGLE TIME! I have a python course I'm working through, and its very good, but sometimes it fails to explain things(like name equals main) in a way that is easy to understand. Every time I run into that, I look to see if you have a video on it, and every single time not only do you have a video, but it explains it perfectly in an easily comprehensible way. Thank you for these. I hope you are making some money off them because they are wonderful.
@soul-monk8 жыл бұрын
perfectly explained ..thx a lot confusion removed ...
@sbsyr55554 жыл бұрын
Superb explanation......👌👌👌 I could have first watched this video instead of searching explanation in stack overflow so that my 30 mins is saved....Thank you very much....
@tammytreit38775 жыл бұрын
Thanks, clear and super helpful to this beginner!
@thehonestabe5 жыл бұрын
The way you explain it is so clear and very good. I guess because you really wanna teach and your main goal is to teach people and be helpful. First video watched from your channel and I subscribed. Thank you very much!
@tnmyk_2 жыл бұрын
This is EPIC! Thanks a lot for making this video!
@sixadamra4 жыл бұрын
5 years later this video is still great. Thanks for this explanation, it clears up the concept perfectly.
@raj13076 жыл бұрын
I found your explanation best........Thank you so much..!!
@potatoesama57894 жыл бұрын
tomorrow is 2021 and this channel still has the vest python explanation ever !!
@ytb93holmes5 жыл бұрын
Clear conception. And other puzzle is that I'm interested in learning how to execute and preview the result on sublime text after finishing python?
@dusanbiga49485 жыл бұрын
Probably figured out by now but sublime is a texteditor and not a IDLE.
@NotxarbProd5 жыл бұрын
CTRL-B
@MrinmoyHaloi3 жыл бұрын
Change build system to python3 and then ctrl+b
@JoeChang-u4v3 жыл бұрын
Thanks, this is definitely by far the simplest and clearest explanation I've read.
@Nonplused4 жыл бұрын
I'll be watching more of these videos for sure. My 14 year old son is learning to program in Python, but of course in my day Visual Basic was all the thing, so I have a hard time helping him even though I am very good with VB. The syntax is quite a bit different and the way people use Python is also quite a bit different. Even just the fact that logical statements like if, while, for etc. don't need to be terminated but rely on formatting is new to me. No more "end if". Visual Basic is more like Visual Pascal only without dynamic variables. Shows how old I am. And when did we go back to running stuff from the command prompt? It took me an hour to figure out how to get my computer to launch python that way even with the help of a video. Mind you I wasn't very familiar with setting system variables. I also really miss the "Step" debugger function in VB. I found something similar in Python but since half the time you are in imported code I have no idea what it is pointing at. My son would joke "oh look we are at line 1048 of my 50 lines of code". A video on how that works would be great.
@ritikaprasai51184 жыл бұрын
You are the best tutor on you tube! Thank you for your wonderful videos. Please add more videos with real world problems.
@pyTechLife5 жыл бұрын
Finally got this. Thank you a lot!
@akira_asahi2 жыл бұрын
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@rubialugattimoreira19782 жыл бұрын
Best explanation! 👏👏
@easydatascience25082 жыл бұрын
See mine too. The channel has Python crash tutorials, and R beginning course tutorials. Step by step, sequentially. And you can download all the source files (can be found in the description of the video).
@cemalcakir4 жыл бұрын
I love how you explain concepts with just 4-5 lines of code.
@gustavo_yohan5 жыл бұрын
Very helpfull video , thanks for upload this video
@aidianpapallo19304 жыл бұрын
The no parenthesis around the pront spooked me, but great tutorial, glad i found it!
@luijo6335 жыл бұрын
You just cured my anxiety
@Joy_Deep2913 ай бұрын
bro You explained it so well. I was confused for so long even after watching other vids. you sir have earned my sub
@susarlaaditya56295 жыл бұрын
Subscribed: Man you explained very well!
@egemen_ozturk3 жыл бұрын
I cannot believe how good this explanation is.
@gherbihicham85065 жыл бұрын
Coming up from a C++ and Java world I use the "if __name__ == '__main__':" functionality almost religiously, even though most of the time I dont need it.
@qwerasdfhjkio5 жыл бұрын
___name___
@simonfelix91384 жыл бұрын
Crystal clear and very helpful series of videos. You seem to acutely anticipate areas of confusion for an audience who is looking at the topic with a fresh pair of eyes and then proceed to clarify these doubts with simple but complete explanations and back it up with relevant examples. There are loads of online paid courses that fall far short from the level of your videos. Kudos. Wish someone could teach the hosts of instructors and trainers out there to emulate your capabilities, many of these courses seem to frustrate new students more than help them.
@andrewluo60885 жыл бұрын
I am from china my teacher never explain these things to us thank god i have find this video
@Hephasto4 жыл бұрын
Andrew Luo do you ask him to explain ?
@realnice36724 жыл бұрын
@@Hephasto maybe he is introvert.
@RuinousGrace4 жыл бұрын
It's funny how almost no tutorials I've seen cover this statement, given how incredibly common it is. Thank you very much!