What is the difference between a statement and an expression?

Programming

26 Jan 2020 | 1 minute read

The distinction between a statement and an expression can be somewhat confusing. Let's make their difference as simple as possible.

  • A statement does something.
  • An expression produces at least one value.

As of this, an expression is part of a statement, because, in order to produce something, you have to do something.

Python

In Python, the following would be a statement.

print("Hello World")

Why? It returns nothing. Do you think the following is a statement or an expression?

1337 + 1337

It's an expression, as it will produce and returns the value 2674.

Hopefully, the difference is a bit clearer now!

Stay in the loop

If you want to take part of new articles and tips and tricks to become a better developer, subscribe to my private email list:

Your thoughts? Please leave a reply 💬