Here are the python files which are used for the tutorial in Medium
https://punjdeep.medium.com/let-me-convince-you-to-use-if-name-main-in-python-ca98a2766a6
Here are the python files which are used for the tutorial in Medium
https://punjdeep.medium.com/let-me-convince-you-to-use-if-name-main-in-python-ca98a2766a6
print("Usage of if __name__ = \"__main__\"") | |
# let us define a function | |
def NumSquare(num): | |
print("Begining of the function") | |
squaredValue = num**2 | |
print("Square of {} is {}".format(num, squaredValue)) | |
print("End of the function") | |
return squaredValue |
print("Usage of if __name__ = \"__main__\"") | |
# let us define a function | |
def NumSquare(num): | |
print("*"*10) # this is to make the a little more visible. | |
print("Beginning of the function") | |
sqrdVal = num**2 | |
print("*"*10) | |
print("Square of {} is {}".format(num, sqrdVal)) | |
print("*"*10) | |
print("End of the function") | |
print("*"*10) | |
return sqrdVal | |
if __name__ == "__main__": | |
num = 10 | |
sqrdVal = NumSquare(num) | |
print(f"Output is : {sqrdVal}") |
print("Usage of if __name__ = \"__main__\"") | |
# let us define a function | |
def NumSquare(num): | |
sqrdVal = num**2 | |
return sqrdVal | |
def AnotherFuction(txtData): | |
return txtData | |
def extraFunc(value): | |
## this function will only work if you import | |
## the file in a python interpreter. | |
output = value*2 | |
return output | |
def main(): | |
print('*'*10) | |
num = 10 | |
sqrdVal = NumSquare(num) | |
print(f"Output is : {sqrdVal}") | |
print('*'*10) | |
data = "an explanation of the main fuction" | |
print("This is "+ AnotherFuction(data)) | |
if __name__ == "__main__": | |
main() |