Python's if __name__ == "__main__" Explained

Опубликовано: 18 Сентябрь 2023
на канале: Darcy DeClute
6,394
126

Ever wonder what Python's "if name == main" construct does?

This Python tutorial will quickly explain what the if name == main condition does when added to your code.

The quick explanation?

Any time you want a single-point of entry for your Python apps, just put the code that kicks off your app in this block:

if _name_ == '__main__':

Then, when you run your Python app as a standalone application, the code in the if __name__=="__main__" block runs.

This is a smart approach if you want either run or import Python code as a library or a component.

It's similar to the void main() syntax of Java. C and C++ has similar constructs.

So there you go, that's the answer to the age old question of what does Python's if __name__=="__main__": do.

⏲️ KEY MOMENTS ⏲️
------------------------------------------
00:00 - Python Tutorial Intro
00:21 - Python Libraries
00:33 - Top Level Code
00:46 - if name == main
01:00 - Python Components
01:11 - if name == main example
02:30 - Python vs Java
03:09 - Scrum for Python!
03:20 - Is it Over?


На этой странице сайта вы можете посмотреть видео онлайн Python's if __name__ == "__main__" Explained длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Darcy DeClute 18 Сентябрь 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 6,394 раз и оно понравилось 126 зрителям. Приятного просмотра!