0
Can anyone explain it briefly, How it will print Welcome?
if __name__== "__main__": print("Hi") else: print("Welcome")
2 Réponses
+ 1
if __name__ == "__main__"
these lines are used to determine if the module was included in another file, or run by itself.
if __name__ is indeed __main__ then it means the script is the "main" script running, i.e. you ran it on it's own. this is often used to execute some example code for a library/module.
if __name__ is not __main__ this means you have included the script as a module in another script. this means the code after the if statement will not execute.
0
== stands for equal , basically you are telling the program if the name is equal to main print hi, if it is not equal print welcome