Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python flow of execution

Tags:

python

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.

like image 298
user5769010 Avatar asked Apr 27 '26 07:04

user5769010


1 Answers

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)

like image 166
Yoav Glazner Avatar answered Apr 28 '26 19:04

Yoav Glazner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!