If __name__ == "__main__" for Python Developers

383,469
0
Published 2022-11-27
If name equals main - then we run our programs!
But do we actually understand what is _name_ , what is _main_ and most of all - why do we need to check if they match? πŸ€”πŸ€”πŸ€”
I've prepared this very special tutorial that dives deep into each component and demonstrates it thorough simple code examples. By the end of this video - you'll be able to explain this expression in your own words (!!!) as well as other terms like "module" and even "top level code" πŸ˜‰

⏰ TIME STAMPS ⏰
------------------------------------------
00:00 - Intro
00:29 - What is _name_
00:59 - What is module?
01:34 - Top level code vs imported code
03:35 - What is _main_
05:08 - Find the value of _name_
05:55 - Why do we need to check if name == main
08:08 - Thanks for watching!

🀝 Connect with me 🀝
--------------------------------------
πŸ”— Github:
github.com/mariyasha
πŸ”— Discord:
discord.com/invite/wgTTmsWmXA
πŸ”— LinkedIn:
ca.linkedin.com/in/mariyasha888
πŸ”— Twitter:
twitter.com/mariyasha888
πŸ”— Blog:
www.pythonsimplified.org/

🎯 Sources 🎯
--------------------------------------
⭐ Python Documentation:
docs.python.org/3/library/__main__.html

πŸ’³ Credits πŸ’³
----------------------
⭐ Beautiful animated graphics by:
mixkit.co
⭐ Beautiful icons by:
flaticon.com

#python #pythonprogramming #python3 #pythonforbeginners #if #main #coding #programming #pythontutorial #conditioning #pythonsimplified #module #toplevel #code

All Comments (21)
  • @supermalavox
    I like it when youtubers describe their code(s) verbally as they go along. For a blind person such as myself, it is of great help, since screen readers normally don't speak the contents inside videos, only in their descriptions, so if you say what you are doing while you write/show the code, the explanation becomes accessible! Thanks and keep up the good work!
  • Did you guys watch the video at all before commenting? Please watch it. That's how you will learn. She is here to educate, not for fans.
  • @michalbotor
    you've achieved mastery in clean, logical, and engaging explanations of programming concepts. my understanding of the topic has increased substantially. thanks so much mariya!
  • @MrKrtek00
    This was actually way more insightful than I expected... Thanks, great explanation!
  • @Richie.P71
    I have been wondering this for ages, thank you for breaking it down so simply. You are the best!!
  • @ssloc
    So thorough with great examples/visuals! Great job πŸ‘. I look forward to more.
  • @EmaMazzi76
    Your lessons Mariya really worth every seconds spent…watched dozens of videos regarding this topic (if _name_ == β€œ__main__”…) and for the very first time I understand what it does actually πŸ˜„ thank you, thank you, thank you
  • @NoOne-L
    Wow! Your channel was recommended to me a few months back and I kept passing it. Glad I finally watched 1 of your video. You’re such a great teacher. You make complex stuff simple. Thanks and will watch more videos from you
  • I am a French developer, beginner in python, and your tutorial is extremely clear, I understood everything! I often avoid English tutorials because the YouTuber speaks quickly and I have trouble following but here I have nothing to complain about, your English is simple and easy to understand. I subscribe to your channel +1. Thank you very much for this wonderful work. This is the first time I've posted a message on Youtube in my entire life πŸ˜‚ but it's well deserved !πŸ‘πŸ™
  • @portinho199
    As always, the best and cleary explanation from entire Youtube platform. Thank you so much!!!
  • @hiutale
    I'm purely amazed by your explanations! I only had to backtrack (a bit) once to understand all of it even though I'm still a beginner. You are the hero function we needed to call! 😭😭πŸ₯Ίβ€οΈπŸ™βœ¨
  • Excellent explanation! You have included some essential features of this statement that makes it all so much more understandable, unlike many other explanations I have seen on YouTube. Thanks!
  • This was such a good video! I've always been curious about this, but never really looked it up. Now it makes sense :) Thanks for the clear explanation!
  • @jcmschott1895
    Amazing content! Pleeease keep it up! You built it up like a crescendo and suddenly became crystal clear why this "if __name == __main__:" stuff is so necessary.
  • I used to scroll down and pass your videos but now i am hooked as your methods of teaching is really easy. Thanks again
  • @MrIsaacpr7
    I’m really enjoying your videos a lot. I’ve been wondering why I write that exact line of code for weeks, with no clue as to why. Once again, you nailed it! Your way of explaining things in a digestible manner for a total beginner is unparalleled. Thank you for sharing.
  • @hondacars8444
    Great video. Thorough yet succinctly presented. Awesome job πŸ‘πŸ»
  • So much quality in this video. Simply perfection. Even thought I know a lot about if _name_ == '__main__' I found an additional information I've never know.
  • @RunePedersen
    What a super wonderful and crystal clear way of explaining. :-) Thanks lot Mariya!
  • @PARTner91
    If only everyone could explain things as clearly as you do. Nice job, thank you.