+ 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 odpowiedzi
+ 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