i

Python Programming

Python Function

Introduction

Function is reusable code used to perform any action. For example if any code is concurrently to be used in different program that code to be stored in a function and can be called any times in different programs.

Python has many built in functions like print() type() etc. These are built in function of python which we generally used in any program. Similar way user function can be called that is called user-defined functions.

Defining a Function

Following are the rules of functions:

Function start with keyword def by the function name with parenthesis. For example def test() here def is keyword and test is function followed by parenthesis. Return statement passing back a value. We will discuss with example to understand more clearly. Every function starts with colon (:) as shown in below example/

def (parameters):

…function logic #... is white space or tab after function.

Return[exp]

Example

Below is example of printing a string.

Output:return # it will return string abc and show the result.