i

Python Programming

Calling a function

In python any function can be called by other function in the same program.

Live Demo

#!/usr/bin/python

When the above program run it will give following output.

Output:“Hello this is python”

Passing by reference vs value

Every parameters in python are passed using reference. For example:

Live Demo

Here, we are maintaining the reference of the passed object and appending values in the same object. So, this would produce the following result –

Output:

Value present inside the function:[1,4,5,6]

Values outside the function:  [11,20,33]

Below is example where argument passed by reference and being overwritten inside called function.

Live Demo

The parameter list is local to the function change. Changing list within the function does not affect list.

Output:

Values in the function:  [1, 2, 3, 4]

Values out-sidefunction:  [10, 20, 30]