Expressions and Statements in Python

Author
By Darío Rivera
Posted On in Python

A statement is an execution unit, while an expression is an evaluation unit. Simply put, everything that returns a value in Python is an expression. Understanding this will help you create clearer and cleaner programs.

Let's look at the following program as an example:

import platform

version = platform.python_version()

print('This is python version {}'.format(version))

The first line is a statement, it does not return any value, but can be executed by itself to import platform. This means that every line of code in Python is a statement. The third line of code is both a statement (as it is a line of code) and an expression since we are assigning a value to a variable. Finally, the last line is also an expression since although we are not explicitly assigning the value of a function, the function itself is returning a value.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.