Code __init__ | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Code __init__

What does the result of this code: def function(): print("This is a module function") if __name__=="__main__": print("This is a script")

24th Jul 2018, 5:16 AM
David
2 Respostas
+ 3
Okay I assume you know what function() is (else you failed to learn Python šŸ˜‚) __name__ returns the name of the instance where it is running. Suppose this script was impirted as a module, __name__=="__main__" will be false, hence it will not run. It will only run IF it is run as a script.
24th Jul 2018, 5:54 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar
+ 2
why don't you try on python idle and verify?
24th Jul 2018, 5:48 AM
$Ā¢šŽā‚¹š”­!šØš“
$Ā¢šŽā‚¹š”­!šØš“ - avatar