📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 95question

PYTHON FUNCTIONS

Chapter 2: 3 · COMPUTER SCIENCE

PYTHON FUNCTIONS Main advantages of functions are • It avoids repetition and makes high degree of code reusing. • It provides better modularity for your application. Functions are nothing but a group of related statements that perform a specific task. Note .

. Types of Functions Basically, we can divide functions into the following types: User-defined Functions Built-in Functions Lambda Functions Recursion Functions Figure – . – Types of Python Functions Functions Description User-defined functions Functions defined by the users themselves. Built-in functions Functions that are inbuilt with in Python.

Lambda functions Functions that are anonymous un-named function. 12th Computer Chapter - - Recursion functions Functions that calls itself is known as recursive. Table – . – Python Functions and it's Description Defining Functions .

Functions must be defined, to create and use certain functionality. There are many built-in functions that comes with the language python (for instance, the print() function), but you can also define your own function. When defining functions there are multiple things that need to be noted; • Function blocks begin with the keyword “def” followed by function name and parenthesis (). • If any input parameters are present should be placed within these parentheses when you define a function.

• The code block always comes after a colon (:) and is indented. • The statement “return [expression]” exits a function, optionally passing back an expression to the caller. A “return” with no arguments is the same as return None. Python keywords should not be used as function name.

Note . . Syntax for User defined function def < ([parameter1, parameter2…] )> : <Block of Statements> return <expression / None> In the above Syntax, the Text which is given in square bracket [] is optional. Note A block is one or more lines of code , grouped together so that they are treated as one big sequence of statements while execution.

In Python, statements in a block are written with indentation . Usually, a block begins when a line is indented (by four spaces) and all the statements of the

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →