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

Опубликовано: 06 Сентябрь 2022
на канале: Python and Pandas with Reuven Lerner
5,358
308

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.

The Jupyter notebook for this video, along with all of them, is at GitHub: https://github.com/reuven/youTube-not....

And don't forget my free, weekly "Better Developers" newsletter, at https://BetterDevelopersWeekly.com/!