In your first year of learning computer science, think of defining a function like naming a recipe.
A function is a special piece of code that you can use again and again to do a specific job.
Function Name: This is what you call your function. For example, calculateArea
.
Parameters: These are the values you give to the function to help it do its job. For example, in calculateArea(length, width)
, length
and width
are the parameters.
Return Value: This is what the function gives back after it has finished its job. For figuring out the area, you can return the result of length
multiplied by width
.
def calculateArea(length, width):
return length * width
In this example, if you use calculateArea(5, 10)
, it gives you back . That’s the area of a rectangle!
In your first year of learning computer science, think of defining a function like naming a recipe.
A function is a special piece of code that you can use again and again to do a specific job.
Function Name: This is what you call your function. For example, calculateArea
.
Parameters: These are the values you give to the function to help it do its job. For example, in calculateArea(length, width)
, length
and width
are the parameters.
Return Value: This is what the function gives back after it has finished its job. For figuring out the area, you can return the result of length
multiplied by width
.
def calculateArea(length, width):
return length * width
In this example, if you use calculateArea(5, 10)
, it gives you back . That’s the area of a rectangle!