What does 'if __name__ == '__main__' ' do in Python?

preview_player
Показать описание
One of the most common, and most misunderstood, lines in Python involves a variable __name__ and a string '__main__', and typically appears at the end of a module file. What does this line do? Is it required? How does it work?

In this video, I explain how this all works, and how you might want to use it in your own programs.

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

I've watched 5 videos, but yours in jupytrr notebook finally clicked for me since I use jupytrr notebook too. ty so much. sub and liked!

Diamond_Hanz
Автор

Magnificent explanation
Cleared all the doubts in such a simple manner.
I recently came across your channel & have been hooked since then for python content.

Request you to release OOPs concepts videos as well, would be really helpful to learn oops concepts from a teacher like you:)

Thanks much sharing your knowledge

Anonymous_it_is
Автор

So far best explanation I found on this topic. Thanks!

ThePeacefullOasis
Автор

Well, I never! I couldn't work this out until now. Thanks.

richpeacock
Автор

An excellent explanation. Thank you. A valuable time investment. Very well done.

davidbacon
Автор

Very well explained! As others have said in the comments it's the best explanation I have found so far on this topic.

PaulFWatts
Автор

I was confused by this for while, but thanks for the clarifying so well 😊😊. Thanks

takshpatel
Автор

Great explanation. Any plans for similar C++ tutorials? ;)

kwaczorek
Автор

Excellent video! Clear, consice, and now I understand. Thanks!

enpassant
Автор

thanks . so clear and helpful . best on this topic

anastasiiaandrusyshyna
Автор

Better at least ! This particular function: if __name__= __main__ has been very confusing to me. But, bit by bit I'm getting to see its relevance. Thanks

funnyclips
Автор

waw, this is one thing i never knew of, thank you Reuven

BytesofNow
Автор

Thanks for the lesson. It was thorough and clear!

xhhhhff
Автор

Hey, thanks for this one more subscriber added i have been using python flask for a while and this line is very important but i didn't understand it

faseunoluwatobiloba
Автор

Thanks for this, excellent explanation, subscribed :)

theclimateposts
Автор

Hey, thanks for the lesson! I have a question that i need a second opinion on. I just got in college taking Computer engineering. My career goal is to be a software developer, but I decided to pick computer engineering instead of comsci as it was more flexible in terms of job opportunities according to my research. I have already started learning programming before going to college. Currently we are on our 4th week of our classes and i am already bombarded with math and chemistry lessons. These past week i've been studying from morning to night for these two subjects, and i don't even think they're that necessary for my career goal as a software developer. I've seriously been thinking of dropping out, and self studying to be a software developer. I am disciplined and i will study for 8 hours if i have to. Can i get your opinion on this?

nateF
Автор

I never understand the purpose of the line if this is always True. Now, I understand. It isn't something nerd will add to make thing cool.

zigaudrey
Автор

Do you know how to make python main.py work

ShayanMK