Python Tutorial for Beginners 40 - Idea behind : if __name__ == '__main__'

preview_player
Показать описание
In this Python Tutorial for Beginners video I am going to show you the Idea behind using : if __name__ == "__main__" in Python. __name__ is a built in variable in Python. the value of __name__ is set to "__main__" at runtime. Each module has a name, and this name can be used to access instructions in a module. This is especially useful in a given situation: As mentioned before, the main block of a module is executed when it is imported for the first time. But what do we do if we want the block to run only if the module was started as a stand-alone program, but not if it was imported from another module? We can do this by evaluating the attribute __name__ of the module.

#PythonTutorialforBeginners #ProgrammingKnowledge #LearnPython #PythonCourse
★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Рекомендации по теме
Комментарии
Автор

This is probably the best explanation of if name ==Main I’ve ever seen. Great job!

officesuperhero
Автор

First time ever I understood it after watching thousand videos on youtube. Thank you. God bless you.

flamboyantperson
Автор

Probably the best explanation (which made sense) I've found. Cleared this understanding up for me. Thank you.

MarcMcRae
Автор

Finally, someone explained it clear!!! I watched dozens of vids but still didn't understand it.
So basically, this code blocks whatever is below it when the module is used in the main code

hturtyada
Автор

Very clear explanation, even stack overflow messed the explanation. Great job!!

lyfsfast
Автор

Thank you very much for explanation and showing how to use it and the difference. Well done

MrLeonardodv
Автор

Best explanation out there! Clear and concise.
Subbed

akubishon
Автор

Was able to understand clearly only after seeing this video . Best of them all.

anilsangani
Автор

Best explanation I´ve found on the internet, good job!

servacjanekvanik
Автор

amazing explanation thank you for helping me further understand this topic

jingasura
Автор

Sir, u are great. a very nice concept of __name == __main__

akshatbhutra
Автор

Mate, excellent explanation! Thanks you so much for explaining!

Schweppese
Автор

Thanks a ton man! This explanation was really useful and is probably the best explanation of the if __name__ =__'main__' statement.

gauravbhat
Автор

Thanks man, the best explanation on the topic so far!

juliusvaidila
Автор

Yureka!Thanks this finally help me understanding if name == main.

Kamekitu
Автор

finally i understood it. thank you very much

utkuaslan
Автор

Great. I think you are teaching a brand new Python tutorial again. I hope you will do the same for C programming and Java programming tutorials.

satishwdesh
Автор

wow
you elucidated this topic
note : if something is wrong with my English plz correct me

unnatigoel
Автор

You are the best sir. Even better than bucky roberts(he is funny and doesn't bores us but still u explain a bit better)

shalinisahnimankatalia
Автор

Will you also take lessons about module importing in python ?

hueseyinguendogan