Example : Writing and calling method
def hello(text):
print("Hello " + text)
# If statement below checks is from the main thread
if __name__ == "__main__":
hello("world")
def defines a method hello with parameter names.
Method starts just after the colon :
If condition __name__ == "__main__" checks if the call is from main process.
If block also starts just after colon :
Next line is the call to hello method with some value.
When you run the program using python hello.py
It gives result : Hello world
No comments:
Post a Comment
Note: only a member of this blog may post a comment.