Тёмный

if __name__ == "__main__" in Python The Real Reason | Why we use this in Python 

robotrakesh
Подписаться 150
Просмотров 3,2 тыс.
50% 1

Welcome to today's video where we dive into one of the most fundamental concepts in Python programming: _name_ == '__main__'. Understanding this concept is crucial for every Python developer, whether you're a beginner or seasoned coder.
mastering _name_ == '__main__' empowers you to write cleaner, more modular Python scripts that are robust and scalable. Whether you're writing scripts for personal projects or enterprise applications, understanding this fundamental concept will elevate your Python programming skills.
Related Queries
if _name_ == "__main__" in python
how to use _name_ == "main" in python
python name main
python name == main
name == main in python

Опубликовано:

 

5 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 10   
@ebraheemelsharkawy3858
@ebraheemelsharkawy3858 Месяц назад
Helpful, concise, and to the point. Thank you for making this video!
@dan-us6nk
@dan-us6nk Месяц назад
The ending still isn't clear. What do you mean by "accidentally executing the module while importing it"?
@pratikpal5565
@pratikpal5565 Месяц назад
Cause you call the function in the same file.
@top5things895
@top5things895 Месяц назад
When we use if __name__ == '__main__', we are checking whether the current program is being run directly or being imported as a module into another program. If we import the first file into a second one without if __name__ == '__main__', Python will execute the code in the first file without distinguishing whether it is being run as the main program or not. By using if __name__ == '__main__', we ensure that the hello() function is specifically executed only when the first program file is run directly as the main file. I hope this explanation helps clarify the usage and importance of if __name__ == '__main__'
@daveit1337
@daveit1337 Месяц назад
What does __name__ contain when it's run within the imported module?
@top5things895
@top5things895 Месяц назад
It will return the name of imported module , let say file1.py contain print(__name__) , then it will print "file1"
@IvanToshkov
@IvanToshkov 22 дня назад
Here is my take. This construct is obviously a hack. I can't believe that Guido van Rossum would have designed modules this way if he had included them from the start. So I'd guess that modules in python were a later addition and he designed them in a way that is relatively simple to implement. However, this created the problem that just importing a module would execute any top-level code and this hack was the solution. I'd love to hear the real story behind those and see how far I'm off the target. :)
@atmiaesatruemasterisaneter664
@atmiaesatruemasterisaneter664 Месяц назад
Thanks man, I always wondered why that exists
@top5things895
@top5things895 Месяц назад
I'm glad you found it helpful!
Далее
If __name__ == "__main__" for Python Developers
8:47
Просмотров 394 тыс.
5 Good Python Habits
17:35
Просмотров 482 тыс.
NOOOO 😂😂😂
00:14
Просмотров 4,2 млн
Can you do that⁉️ #beauty
00:16
Просмотров 1,4 млн
БАТЯ В ДЕПРЕССИИ
00:52
Просмотров 638 тыс.
*Next-door 10x Software Engineer* [FULL]
4:50
Просмотров 488 тыс.
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн
5 Awful Python Mistakes To Avoid
22:13
Просмотров 25 тыс.
Dice Don't Normally Look Like This...
4:03
Просмотров 10 тыс.
Never install locally
5:45
Просмотров 1,8 млн
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 304 тыс.
21 MORE nooby Python habits
9:55
Просмотров 115 тыс.
I Hacked a Discord Bot, the Owner said this...
9:09
Просмотров 1,2 млн
5 Useful F-String Tricks In Python
10:02
Просмотров 292 тыс.