Python is an object-oriented programming language ideally designed for rapid prototyping of complex applications. Like Perl, Python source code is also available under the GNU General Public License (GPL).

In this article we will see, How to define and call a function in Python.


1) Defining and calling a function in python:

In Python functions are defined by the "def" keyword followed by the function name and parentheses ():. The code within every function starts with a colon (:) and should be indented (space),
def printName():
	print 'tbNext';

#Already defined function can be called as follows:

printName()

Output: Output will be something like this:

tbNext


2) Defining and calling a parameteriszed function in python:

def printName(number):
	print number*number;

printName(3)

Output: Output will be something like this:

9


3) Defining and calling a function in python with return value:

def printName(number):
	return number*number;

print printName(3)

Output: Output will be something like this:

9


In this article we have seen, How to define and call a function in Python. In upcoming articles we will see more complex usecases and tricks of python.
  • By Techburps.com
  • Sep 30, 2017
  • Python