Can anyone explain it briefly, How it will print Welcome? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone explain it briefly, How it will print Welcome?

if __name__== "__main__": print("Hi") else: print("Welcome")

8th Nov 2016, 8:05 AM
Sourav Kumar
Sourav Kumar - avatar
2 Answers
+ 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.
20th Nov 2016, 4:56 PM
asdadasdsaczxc
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
10th Nov 2016, 6:13 AM
Sharoek Mahboeb
Sharoek Mahboeb - avatar