Cits 3
Cits 3
To execute a function, you must call it i.e., give the name of the function
followed by a set of parentheses.
What is a function?
For example: greet()
“A function is a group of statements that exist within a program for the
purpose of performing a specific task. programmers usually break down their
programs into small manageable pieces known as functions”.
Defining a function:
“A function definition specifies the name of a new function and the sequence
of statements that execute when the function is called.”
Function name
Function
header def greet():
Function Passing information to a function
print("Hello!") definition
Block of
statements print(“Welcome!") Information that's passed to a function is called an argument;
information that's received by a function is called a parameter.
“The first line is known as the function header. It marks the beginning of the Arguments are included in parentheses after the function's name, and
function definition. The function header begins with the key word def, parameters are listed in parentheses in the function's definition.
followed by the name of the function, followed by a set of parentheses, ◦ Example: Passing a single argument
followed by a colon.” parameter