Calling a function

You might be wondering what is calling a function. Now, let's suppose you wrote some business logic about washing instructions to be embedded inside an automatic washing machine. Let's say you want to time sequence for rinsing of clothes immediately after wash. In programming language, you don't want to get lost writing a big chunk of program, so, in order to make things easy, you write your business logic inside a function. This function has to be called when you want that particular sequence to be timed right after the washing sequence finishes. There you pass the execution of instruction to the function written for timing of sequence. This is achieved by calling the function at an appropriate time.

Syntax block of code is:

function_name(arguments)

A function can be called within a programming construct similar to the built-in function. Use the name of the function followed by a set of parentheses. A function can be called any number of times within the same programming file, or another, or can be called within another function. Yes you got it right: a function can call another function. Let's learn from an example:

def helloWorld(): 
""" This is Hello World Program"""
print "You are in Hello World"

helloWorld()

Here, we define the helloWorld() function and we give a body, which has a comment and a print statement. Finally, we simply call the function by merely typing the name of the function followed by parentheses. When the program is run, we get the output as shown here:

There are various ways in which a function can be written or exists in any programming language. We will discuss various ways in which a function can be formed in Python. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.73.207