Что значит __name__ == "__main__"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Что значит __name__ == "__main__"?

Уже несколько раз видел это, а сейчас когда скачал pycharm вижу снова https://code.sololearn.com/cBomur3V8w4E/?ref=app

30th Dec 2020, 11:00 AM
😎_M_😎
😎_M_😎 - avatar
1 Answer
+ 2
All it does is make sure that the module wasnt imported. Sometimes you can have "main code" that runs when you execute the file itself. But if you just want to use a couple functions in the file, then you can import the whole thing, or just certain functions. when a code is ran directly from a file (it was not imported) than the __name__ IS equal to "__main__". Any code in that block will be ran if the module isnt imported.
30th Dec 2020, 11:10 AM
Slick
Slick - avatar