Python Tutorial: if __name__ == '__main__'

In this video, we will take a look at a common conditional statement in Python:
if __name__ == ‘__main__’:

This conditional is used to check whether a python module is being run directly or being imported.

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –



Xem thêm bài viết khác:


  1. thanks Corey is this python 2 or 3 pleas?

  2. Please make videos related to Machine Learning and Deep Learning too. Your explanation is by far the best on youtube, the content is pure gold. I became an instant fan. Thanks a lot for your videos.

  3. Dear Corey,
    I am recently making my own project (a package) for handling experimental images. I am trying to implement the OOP knowledge I learned from you, such as those dunder methods and properties.
    However, I am still a bit confused by how do some other dunder methods/variables work, such as _future_ found often in the _init_ file. Is it possible to do a tutorial on importing packages?

  4. Definitely the best explanation

  5. Perfect explanation of these magic methods. Cheers!

  6. It's 2020 and this is still the best explanation of this

  7. This is the main video for python 🐍

  8. I understand what it does but I don't get the purpose of this..? what is a real life scenario when you would use this method?

  9. 5 years later this video is still great. Thanks for this explanation, it clears up the concept perfectly.

  10. you explained this topic very easily
    love your explanation

  11. Good tutorial with poor interface

  12. Please make the font bigger so we can see better

  13. Thanks, wanted to know how this works

  14. So for programmers who have come from other languages and are learning pythons crazy new age way of doing things: if you run that .py file directly then it makes it the main method but if you import it and run that file its not the main method?

  15. Is this no longer valid in Python 3?
    I had the same code as in 5:39 (with parenthesis for print functions) and I received "Run From Import" despite it being run directly.

  16. What is needed for! What is the first module?

  17. Wow this was explained really clearly. Thanks!

  18. honestly dude, using your videos and with a little help from a friend my coding knowledge has increased so quickly. Your videos are awesome !

Leave a Reply

Your email address will not be published. Required fields are marked *