Can someone explain the flow of execution of a python program especially about the main function? It would be helpful if it is compared and contrasted with execution of C.
when you execute "python myprog.py" the python interpeter will start running the script line by line:
import os #import the os module
print "prints somthing"
def f(num): ... # define a function
a = 5 / 2.0 # calculating stuff stuff ...
if __name__ == '__main__': #__name__ is '__main__' only if this was the file that was started by the interpeter
f(a) #calling the function f...
In C there is special function "main" that will be executed at startup. this (as explained above is NOT true for python)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With