Working With Functions Notes
Working With Functions Notes
Computer Science
Functions:
Types of Functions:
To create a user-defined function, you use the def keyword. The syntax for
creating a user-defined function is as follows:
Code snippet
def function_name(parameters):
# body of the function
Lovejeet Arora
TECHQueenUnacademy
Arguments are the values that are passed to a function when it is called.
Parameters are the variables that are used to receive the arguments that
are passed to a function.
Default Parameters:
Code snippet
Positional Parameters:
Code snippet
function_name(argument1, argument2)
Lovejeet Arora
TECHQueenUnacademy
Functions can return values. The value that is returned by a function is the
value that is assigned to the variable that is used to call the function. The
syntax for returning a value from a function is as follows:
Code snippet
def function_name(parameters):
# body of the function
return value
Flow of Execution:
Scope of a Variable:
The scope of a variable is the part of the program where the variable can
be used. There are two types of scopes in Python: global scope and local
scope.
● Global scope: The global scope is the scope of all variables that are
defined outside of any function.
● Local scope: The local scope is the scope of all variables that are
defined inside a function.
Variables that are defined in the global scope can be used in any scope.
Variables that are defined in a local scope can only be used in the local
scope and in any nested scopes. ****
Lovejeet Arora