Mar-30-2018, 07:02 PM
Hi all. I saw many times files using 'if __name__=='__main__':' even file is a standalone file.
It seemed to me I should use this 'if' only in case of a project, using many files.
It seemed to me I should use this 'if' only in case of a project, using many files.
def fib(n) :
a,b= 0,1
for x in range(n):
print(a,end=' ')
c=b;b=a+b;a=c
fib(9)
print('')
if __name__=='__main__':
print("why this line is printed since the name of the file is 'fibo.py' and not '__main__' ? ")
Output:C:\Users\Sylvain\fs
λ python fibo.py
0 1 1 2 3 5 8 13 21
why this line is printed since the name of the file is 'fibo.py' and not '__main__' ?
