0% found this document useful (0 votes)
5 views3 pages

Functions cpt-7

The document outlines the concept of functions in programming, emphasizing modular programming and the advantages of using functions for code reduction and reuse. It differentiates between library functions and user-defined functions, explains the creation and use of parameters and arguments, and discusses variable scope. Additionally, it covers built-in functions, modules, and the importance of Python's standard library for efficient coding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Functions cpt-7

The document outlines the concept of functions in programming, emphasizing modular programming and the advantages of using functions for code reduction and reuse. It differentiates between library functions and user-defined functions, explains the creation and use of parameters and arguments, and discusses variable scope. Additionally, it covers built-in functions, modules, and the importance of Python's standard library for efficient coding.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FUNCTIONS

1.Modular programming.
The process of dividing a computer program into separate independent blocks of code or separate sub
problems with different names and specific functionalities.

2.Functions.
• functions is used for code reduction, reuse of code.
• This function can be defined as a name group of instructions that accomplish a specific task when
it is invoked.
• A function is a named group of statements developed to solve a sub-problem and returns a value
to other functions when it is called.

3.Types of functions .
There are two types of functions:
• Library functions
• User-defined functions.

4. Advantages of function.
• Once a function is written, it can be reused multiple times within the program, reducing the need
to write the same code repeatedly.
• Functions help break down complex problems into smaller, more manageable pieces, making the
code easier to understand and maintain.
• By organizing code into functions, the overall readability of the program improves, making it easier
for others (or yourself) to read and understand the code.
• Functions can be tested individually, which simplifies the process of identifying and fixing bugs.

5. User defined function.


• Function created by the user to perform specific tasks within a program is called user defined
function.
• We can define our own function while writing the program.

6.Creating a user defined function.


• a function definition begins with def (define).
• The items enclosed in the []square brackets are called parameters.
• they are optional. Hence, a function may or may not have a parameter.
• Function header always ends with the colon :
• A function name should be unique.
• Rules for naming identifiers are also applied for function naming.
• the statements outside the function are not considered as a part of function.
7.Arguments and parameters.
• Parameter are accepted from user within the function itself.
• In programming, an argument is a value that you pass to a function or method when you call it.
• Arguments provide the necessary data for the function to operate on and produce a result.
• Parameters are part of the function declaration.
• while arguments are used in the function call.
• Parameters define what kind of data the function can accept.
• whereas arguments are the actual data provided to the function.

8. Strings as parameters.
• The humans are passed numeric type only.
• In some program,user may need to pass string values as an argument.

9.Default parameter.
• Python allows assigning a default value to the parameter.
• If a function does not have a argument a default value is predecided and assigned to the
parameter.
• Parameters should have same order of arguments.

10. Functions returning value.


• In python function can return values using returns statement.
• When function returns value we can store that value in variable are used it other parts of our code.
• Functions which does not return any value such functions are called void functions.
We can send values from function to its calling function using return statement .
1. Return the control to calling function.
2. Return value(s) or none.

11. Flow of execution.


• Love execution can be defined as the order in which the statements in a program are executed.
• In python interpreter the statements are executed one by one from top to bottom.
• The statement inside the function are not executed until the function is called.
• A function must be defined before its call within a function.

12. Scope of variables.


• Variable defined inside a function cannot be accessed outside it.
• Every variable as a well defined accessibility.
• The part of the program where are variable is accessible can be defined as the scope of that
variable.
• Variable with global scope is called a global variable.
• Variable with the local scope is called a local variable.

13. Global variable.


• Variable that is defined outside any function or any block is called a global variable.
• It can be accessed in any functions defined outwards.
• Any change made to the global variable will impact all the functions in the program where the
variable can be accessed.

14. Local variable.


• Variable defined inside any function or a block is called local variable.
• It can be exist only in function or block where it is defined.
• It exist only till the function executes.

15. Python standard library.


Python as a very extensive standard library please a collection of many built in functions that can be
called in the program when required.
The saving the programmers time of creating those commonly used functions every time.

16.Built in functions.
• Built in function are the predefine function in python that a frequently used in programs.
• Reset of instruction to be executed for these built in function already defined in python
interpreter.

17. Module.
• The program is divided into different parts under different levels called modules.
• A function is a grouping of instructions a module is a grouping of functions.
• As we know that when a program grows a function is used to simplify code and avoid repetition.
• We can save the functions under module and reuse them.
• A model is created as python (.py) file containing the collection of function definitions.
• To use some module we need import the module.
• To call a function of a module the function name should be preceded with the name of module
• with the (.) dot a separator.

You might also like