If __name__ == '__main__' (with animations) Python Tutorial

preview_player
Показать описание
In this video we will look at the
ubiquitous yet mysterious line of code, If __name__ == "__main__" that pops up in many Python scripts. When I first started, I was wondering why we use __name__ == __main__. If __name__ == "__main__" is actually a way to check if your script is a script or module. If you don't understand that, don't worry, everything is explained in the video.
In this video, we will learn with clear examples why we use if __name__ == "__main__", what each of the components (__name__) and __main__ mean,
I give clear examples with animations to show what this line means,
as well as how to and when to use it and you should hopefully leave this video with a full grasp of the meaning behind the mysterious statment:

if __name__ == "__main__"

You can find the notebook here in my Python stuff repository (or can be found eventually):

Рекомендации по теме
Комментарии
Автор

If the audio quality sound a little strange, sorry about that. Ran a few issues with my PC and audio filtering.

PyMoondra
Автор

Finally a clear and concise explanation after several Youtube videos, thank you very much.

bedeamadi
Автор

Your explanation is soooo much better than others. It seemed so hard and confusing but it's actually a really simple concept. Why do others explain so badly. Anyhow. Thank you a ton! :)

nika
Автор

This is the best explanation on YouTube. I was reluctant to click on it thinking I will end up on an indian tutorial channel.

batmanfromnorth
Автор

Don't worry about the sound. Your explanation is great. Thank you so much :D

mserzysko
Автор

I was struggling with the concept. Your video helped me a lot to get a clear understanding. Thanks.

mosaddeqaziz
Автор

Yes, your explanation is great and very clear. Please keep you very much!!!
If you can group them in the right playlist that's awesome!

tjle
Автор

wow..the best explanation..thanks a lot.

asaoppenheimer
Автор

Good Explanation. Two questions, is the primary use case for testing functions in and out of scripts/modules? Is there any other reason?

shreddychucky
Автор

Thks a lot.. now I really know the logic behind these two...
Do you have a video on importing modules from different folders and sub folders using the path module...thks

rahnluv
Автор

Hey love the videos. Just wondering whats the best practice for having functions you want to import but also a part of the script you'd like to run. Should you just put the function declarations outside of the if __name__ = "__main__": or is it better to break down the file into two, one where you run the script and one where you can import functions?

RedAtruin
Автор

Thanks for your work, you are great teacher

uppercut
Автор

so are you telling me __name__ == "__main__" is the same as 'True'?

AlejandroGonzalez-vioj
welcome to shbcf.ru