Functions
Let’s understand the concept of functions. They are also called subroutines. They are a common programming practice. If a block of code is too long and repetitively used in the program, then we write that block separately from the other code and assign it a name. We call the block using the assigned name wherever needed. Let’s see an example:
def message():
name = input("What is your name, My liege : ")
print("Ashwin is your humble servant, My liege " + name)
print("First function call...")
message()
print("Second function call...")
message()
In this example, we have defined our own function and named it message(). The definition of the function begins with the def keyword. The output is as follows:
>>> %Run -c $EDITOR_CONTENT First function call... What is your name, My liege : Henry V Ashwin is your humble servant, My liege Henry V Second function call...