A Python expression can be defined as any element in our program that evaluates to some value. Well, what does this mean? To understand it better, let us fire up our Python interpreter and take a deep dive into this topic on Python expressions with these examples.

Once in our python interpreter, let us type the following command:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>>
We can see that by simply entering the number ‘4’ into our Python interpreter, it was accepted and evaluated to be of a value of integer 4. Hence, we can say that the input ‘4’ we entered is a type of expression.
Similarly, if we input the command ‘4 + 1’ to the Python interpreter:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>>
Our interpreter goes ahead and computes a value of 4 from this and results in a value of 5. Here too, the input ‘4+1’ can be called an expression as it resulted in a value of 5.
Similarly, if we enter this code to the Python interpreter we get,
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>> "Hello" + "World"
'HelloWorld'
>>>
This too shows that irrespective of the data type used (string in this case as opposed to integers in the earlier examples), a Python expression results in the evaluation of the data (“Hello” and “World”) to a final value (“HelloWorld”). Thus “Hello” + “World” is also a Python expression.
On the other hand, if we take a look at this example:
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 4
4
>>> 4 + 1
5
>>> "Hello" + "World"
'HelloWorld'
>>> result = "Hello" + "World"
>>> result
'HelloWorld'
>>>
Here we are assigning the final evaluated expression value to another variable ‘result’. This type of command where a value is assigned to a variable is called a Python Statement.
So in other words, we can see that a Python statement is made up of one or more Python expressions.
Expression Vs Statement
- Expression
- Expressions always returns a value
- Functions are also expressions. Even a non returning function will still return None value, so it is an expression.
- Can print the result value
- Examples Of Python Expressions: “Hello” + “World”, 4 + 5 etc.
- Statement
- A statement never returns a value
- Cannot print any result
- Examples Of Python Statements: Assignment statements, conditional branching, loops, classes, import, def, try, except, pass, del etc
Summary
In simpler terms, we can say that anything that evaluates to something is a Python expression, while on the other hand, anything that does something is a Python statement. Curious to learn further? Follow our other articles in this blog to know more!
12 replies on “Difference between expression and statement in Python”
[…] Do You Know The Difference Between Expression Vs Statement In Python? […]
[…] Learn this difference between an expression and a statement here […]
[…] Know the difference between an expression Vs statement in Python […]
[…] at 240 MHz. So with these two cores together, this ARM processor is able to run Arduino code, Python and Javascript code as […]
[…] said that, take a look at this article. It gives you a simple explanation on the “Difference between expressions and statements in Python“. I have spent considerable amount of time trying to understand these topics. Since there are […]
It’s very useful. Thanks
You are welcome 🙂 !!
And thanks for commenting, makes my effort to document this worthwhile! 🙂
[…] Add the two numbers by adding the two Python variables using a Python statement (Learn about Python statement here) […]
Thank you so much. It’s really help me.
You are welcome! 🙂
Thank you. It helped me a lot
You are welcome 🙂 Glad you found it useful!