What are some differences between a statement and a function in Python?

Question

In Python, some pieces of code are categorized as statements or as functions. What are some of the main differences between the two?

Answer

In Python, a statement is typically a line of code we write to give an “instruction” or “command” for Python to perform. For example, variable assignment, which we used quite often, is a statement, which tells Python to set a variable to a value, which it carry out when it processes that code line. Statements are essentially always an “imperative” task that must be carried out.

On the other hand, functions are a collection of multiple code lines which you are able to call all at once. Functions themselves are not statements, because they are not an imperative task that must be performed. Rather, they are closer to some object or value, that you can call in your program when you need to run its code.

In addition, statements do not return anything, while functions always return some value, returning the value None if no return value is specified.

32 Likes

That’s a really clear and concise answer!

11 Likes

Is function multiple statements?

3 Likes

yes @digitalpro84845

That cleared things up very nicely. Thank you!

1 Like

Thank you. That was really useful.

1 Like

@jephos249 thank you!
So, basically function is a collection of statements, right?

What about when I am assigning a variable to be equal to the output of a function. Statement?

That is still variable assignment:

So yes, statement.