Objectives


• Understand the concept of function and their types. • Know the diff erence between User defi ned and Built in functions. • Know how to call a function. • Understand the function arguments. • Know Anonymous functions. • Know Mathematical and some String functions.

Summary


• Functions are named blocks of code that are designed to do one specific job. • Types of Functions are User defined, Built-in, lambda and recursion. • Function blocks begin with the keyword “def ” followed by function name and parenthesis (). • A “return” with no arguments is the same as return None. Return statement is optional in python. • In Python, statements in a block should begin with indentation. • A block within a block is called nested block. • Arguments are used to call a function and there are primarily 4 types of functions that one can use: Required arguments, Keyword arguments, Default arguments and Variable-length arguments. • Required arguments are the arguments passed to a function in correct positional order. • Keyword arguments will invoke the function after the parameters are recognized by their parameter names. • A Python function allows to give the default values for parameters in the function definition. We call it as Default argument. • Variable-Length arguments are not specified in the function’s definition and an asterisk (*) is used to define such arguments. • Anonymous Function is a function that is defined without a name. • Scope of variable refers to the part of the program, where it is accessible, i.e., area where you can refer (use) it. • The value returned by a function may be used as an argument for another function in a nested manner. This is called composition. • A function which calls itself is known as recursion. Recursion works like a loop but sometimes it makes more sense to use recursion than loop