https://docs.python.org/3/reference/expressions.html
https://stackoverflow.com/questions/4728073/what-is-the-difference-between-an-expression-and-a-statement-in-python
All Python expressions can be used as statements. Expressions can be reduced to some kind of 'value', but in statements we use 'side effects' (function calls). Expression statements are often used in the interactive mode.
# Expression statements. 2 + 5 # arithmetic or boolean operations name # variable alist[idx] # with lists, tuples, dicts [x for x in iterable] # list|dict|set comprehension some_function() # function call some_object.method() # method call print(word) # function in Py3 (the result is None and a message) yield x ** 2 # in generators lambda x: x ** 2 # anonymous function (lambda function) A if condition else B # conditional expression y := f(x) # assignment expression (Py3.8+)
# Statements, but not expressions. print word # statement in Py2 a = 5 # assignment return name if condition: pass def some_function(): pass class FirstClass: pass