What the difference for function and Procedure in algorithm ??and how is it defined in python? please,help me, I am a beginner in programming
3 Answers
In some languages, there is an explicit difference between the two. And the difference is not necessarily the same in all languages where such a difference exists.
In general, when such a distinction exists, it is implied that the function is 'pure', i.e. it always responds with the same output for the same input, and does not alter the state of the surrounding program. Whereas, a procedure, is more to be thought of as a list of commands, which may or may not take parameters, and operates on the existing space, possibly modifying it as a result.
In python there is no such distinction between 'function' and 'procedure', therefore the two can probably be used interchangeably, although presumably the term 'function' would be preferred.

- 27,810
- 13
- 101
- 139

- 21,371
- 2
- 28
- 57
Basically a function is something that calculates or executes a certain task (add a to b), while a procedure is a set of operations you perform in a certain order or depend on each other.

- 177
- 1
- 13
A function takes arguments and returns a value while a procedure does not return values it just performs a set of instructions.
In python they are both declared the same way using the def keyword and you either end it with a return statement if it's a function or not if it's a procedure
Here is an example of both :
function :
def add(a,b):
return a + b
procedure :
def printFullname(firstname,lastname):
print(firstname + ' ' + lastname)

- 142
- 8
-
1All Python functions return something, even if there is no `return` statement (in this case, they return `None`), and the distinction between function and procedure is inexistent (we only use the term 'function' in all cases). – Thierry Lathuille Feb 28 '21 at 12:16