Ads

Ads


Python Statement vs Function: The Major Difference


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 carries 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 that 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.

Take a look at this (Then Judge)

Image result for python function vs statement
In addition, statements do not return anything, while functions always return some value, returning the value None if no return value is specified.

Post a Comment

0 Comments