Functions
Functions
Laxmi P
PGT-CS
KV Kokrajhar
Functions
■ Output is obtained
Flow of Execution in Function call
Arguments
Passing parameters to functions
■ Positional / Required arguments : All the arguments need to be passed
in function call. We cannot skip any arguments.
■ Default arguments : Parameter having default value in function
header is known as default parameter
– These types of parameters need not be passed during function
call.( if a value is passed for default parameter in function call – it
is overwritten)
interest(prin,time,rate=.10) Legal
interest(prin,time=2,rate=.10) Legal
interest(prin=1500,3,rate=.10) Illegal
interest(prin,time=2,rate) Illegal
interest(prin=1500,time=2,rate=.10) Legal
Namespaces in Python
■ Call by Value
■ Call by Reference
Python-Call-by-Object
■ Python Passes arguments by Call-by-Object
■ Immutable arguments like integers, strings or tuples to a function if
passed, the passing acts like call-by-value.
■ They can't be changed within the function, because they can't be
changed at all, i.e. they are immutable
■ Mutable arguments are also passed by object reference, but they
can be changed in place in the function.
Passing Immutable objects
(Strings,integers,tuples)
■ String