working with functions computer 12
working with functions computer 12
is ● Program:
def display():
print(“hello welcome to python”)
function print(“you are learning about working with
functions”)
? display()
🤔 ● Output :
hello welcome to python
you are learning about working with functions
Increases readability, particularly for longer
code as by using functions, the program is
better organized and easy to understand.
Advanta Reduces code length as same code is not
ges required to be written at multiple places in a
program. This also makes debugging easier.
Of Increases reusability, as function can be
called from another function or another
program. Thus, we can reuse or build upon
Function already defined functions and avoid
repetitions of writing the same piece of code.
s Work can be easily divided among team
members and completed in parallel.
Built in function: These are predefined
function in python and are always available
for use.
def multiply(a,b):
Paramete return a*b
rs
Argument (or Formal parameters)
multiply (4,5)
POSITIONAL /REQUIRED ARGUMENT :
When the function call statement must match the
Positional number and order of arguments as defined in the
function definition, this is called positional argument.
/ Program :
def add(num1, num2,num3):
ts Output :
The sum of maths, chemistry and physics is: 275
Part(s) of program within which a name is legal and
accessible, is called scope of the name.
Types of scope:
1. Global scope
Scope 2. Local scope
Of ● Global variable: Global variable is a variable
defined main program. Such variables are said to have
variables global scope.
● Local variable: Global variable is the available
defined within a function. Such variable are said to
have local scope
◆ Program:
X=5 Global
variable
def fun(X.):