In Python, some pieces of code are categorized as statements or as functions. What are some of the main differences between the two?
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.