Profile photo for Ryan Lam

Here’s a general rule of thumb: If you can print it, or assign it to a variable, it’s an expression. If you can’t, it’s a statement.

Here are some examples of expressions:

  1. 2 + 2 
  2. 3 * 7 
  3. 1 + 2 + 3 * (8 ** 9) - sqrt(4.0) 
  4. min(2, 22) 
  5. max(3, 94) 
  6. round(81.5) 
  7. "foo" 
  8. "bar" 
  9. "foo" + "bar" 
  10. None 
  11. True 
  12. False 
  13. 2 
  14. 3 
  15. 4.0 

All of the above can be printed or assigned to a variable.

Here are some examples of statements:

  1. if CONDITION: 
  2. elif CONDITION: 
  3. else: 
  4. for VARIABLE in SEQUENCE: 
  5. while CONDITION: 
  6. try: 
  7. except EXCEPTION as e: 
  8. class MYCLASS: 
  9. def MYFUNCTION(): 
  10. return SOMETHING 
  11. raise SOMETHING 
  12. with SOMETHING: 

None of the above constructs can be assigned to a variable. They are syntactic elements that serve a purpose, but do not themselves have any intrinsic “value”. In other words, these constructs don’t “evaluate” to anything. Trying to do any of the following, for example, would be absurd, and simply wouldn’t work:

  1. x = if CONDITION: 
  2. y = while CONDITION: 
  3. z = return 42 
  4. foo = for i in range(10): 

Now as for your mentioning of print in Python… it varies. In Python 2, print is a statement, which means it is a single command that does not “evaluate” to anything, and therefore cannot be assigned to a variable. However, in Python 3, print is a function, which is a specific kind of expression.

“But wait!” you object. “If print is an expression, how come we can’t assign it to a variable?”

As it turns out, in Python 3 (but not Python 2) you can assign it to a variable:

  1. x = print(42) 
  2. print("The value of x is:") 
  3. print(x) 

If you run this code, you get the following:

  1. 42 
  2. The value of x is: 
  3. None 

Aha! As it turns out, the print function in Python 3 does have a value. Specifically, its value is None, just like any other function that doesn’t specifically return anything:

  1. def foo(): 
  2. return # This function doesn't return anything. 
  3.  
  4. x = foo() 
  5. print(x) # This will print `None`. 
View 5 other answers to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025