+ 1
__name__ (python)
Hi everyone, Does anybody have an easy explanation of what is __name__ == ‘__main__’ : Sorry I’m not a smart as you :) Just don’t get it
5 Respuestas
+ 2
For simplify __name__ represent the name of program for example "code".
"__main__" is as called the program when he is executed in him same.
Example:
The program name bellow is "code" ,that is , __name__ == "code" of indirectly way ,but when call the command "print(__name__)" he gives back "__main__" because "code" is be executed directly and not indirectly per an import for example.
https://code.sololearn.com/cblxSWcreU6O/?ref=app
+ 1
basically __name__ represent the name of program for example:
"myfirstprogram"
This if program was imported ,but case you will be execute "myfirstprogram" directly ,he called "__main__" ,this is general used in condition for execute an action ,case the program not will be imported ,but can be appliqued in other cases.
Example:
<--CODES-->
First
import Second
Second
if __name__ == "__main__":
print("Is main !")
else:
print("Imported !")
<--EXECUTE-->
First
Imported !
Second
Is main !
• Sorry by some error in answer with English ,my English is bad.
+ 1
which part ? Of __name__ or "__main__".
0
Still don’t get it
0
Both