In programming, there are two important ideas we need to understand: functions and procedures. They help us keep our code neat and organized. But what’s the difference between them? Let’s break it down!
Function: A function is a set of instructions that does a specific job and gives us back a result. Think of it like a calculator. For example, if we create a function called addNumbers(a, b)
, it adds two numbers together and returns the answer.
Here’s how it looks in code:
def addNumbers(a, b):
return a + b
Procedure: A procedure is different. It also does a job, but it doesn’t give us back a result. Imagine it like a recipe that tells you how to bake a cake but doesn’t actually provide the cake. For example, we could have a procedure called printGreeting()
, which simply shows a message.
Here’s an example in code:
def printGreeting():
print("Hello, World!")
So, to sum it up: functions give us results, while procedures do their job without giving anything back!
In programming, there are two important ideas we need to understand: functions and procedures. They help us keep our code neat and organized. But what’s the difference between them? Let’s break it down!
Function: A function is a set of instructions that does a specific job and gives us back a result. Think of it like a calculator. For example, if we create a function called addNumbers(a, b)
, it adds two numbers together and returns the answer.
Here’s how it looks in code:
def addNumbers(a, b):
return a + b
Procedure: A procedure is different. It also does a job, but it doesn’t give us back a result. Imagine it like a recipe that tells you how to bake a cake but doesn’t actually provide the cake. For example, we could have a procedure called printGreeting()
, which simply shows a message.
Here’s an example in code:
def printGreeting():
print("Hello, World!")
So, to sum it up: functions give us results, while procedures do their job without giving anything back!