Jun-03-2018, 07:53 PM
Hi Everyone,
I am a newbie to Python. As I was learning Functions, I am not able to understand the difference between calling the function directly and calling it under __main__. Is there any advantage to call a function under main? Is it something important like main function in Java?
SomeFn() also gets executed directly and funct() also get executed directly.
My sample code:
I am a newbie to Python. As I was learning Functions, I am not able to understand the difference between calling the function directly and calling it under __main__. Is there any advantage to call a function under main? Is it something important like main function in Java?
SomeFn() also gets executed directly and funct() also get executed directly.
My sample code:
def funct(): print("Value of __name__ is: ", __name__) print('This statement is in main function') def someFn(): print ('This function is not called under the main function') someFn() if __name__ == "__main__": funct()Say for e.g., I have 4 functions fn1, fn2, fn3, fn4 - Will there be any difference if I call them by sequence under main or outside main?