Professional Documents
Culture Documents
2 - 3 Functions 1
2 - 3 Functions 1
2 - 3 Functions 1
def function_name(parameters):
"""docstring"""
statement(s)
return [expression]
f (x) = x 2
Above mentioned mathematical function can be written
in Python like this:
def f(x):
return x*x
User-
defined by programmer
defined
Scope
Part(s) of program within which a name is legal and
accessible.
Global Scope
A name declared in top level segment( main ) of a
program, it can be used inside whole program and all
blocks(functions,other blocks).
Local Scope
A name declared in a function-body is said to have local
scope, i.e. it can be used only within this function.