[Tutor] difference between expressions and statements

Danny Yoo dyoo at hashcollision.org
Wed Apr 9 21:04:42 CEST 2014


> Could someone explain the difference between expressions and statements?
>
> I know that expressions are statements that produce a value.

Yes, that's pretty much it.  If you can point your finger at the thing
and say that it produces a value, it's an expression.


> Are any of the following expressions?
>
> print(42)
> print("spam")
> spam = 42
> print(spam)

See:

    https://docs.python.org/2/reference/expressions.html

Technically, the only things that count as expressions have to fit the
shape of something described in that documentation link.



Your question about assignment being an expression or not is something
you can find out by seeing where "Assignment statements" show in:

    https://docs.python.org/2/reference/index.html


Good luck!


More information about the Tutor mailing list