Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deeppunj/d718d5455b5db7d380a51269b221c0d6 to your computer and use it in GitHub Desktop.
Save deeppunj/d718d5455b5db7d380a51269b221c0d6 to your computer and use it in GitHub Desktop.
Python Files for The Medium Story of How to use (if __name__ = "__main__") condition
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment