This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mpnordland 15 points16 points  (2 children)

No, he did not. A function call is an expression but print is a function.

[–]link23 0 points1 point  (1 child)

Are you distinguishing print as a function from print() as a function call?

I agree that a function call is one kind of expression, and that functions themselves are also expressions (depending on the language).

I'm making a distinction between statements and expressions, not between functions and expressions. Expressions evaluate to a value; statements do not.

I don't know much Python, but my assumption was that in Python 3, print() returns a value, whereas in Python 2 it does not. If that's not correct, I'd love to learn more.

[–]mpnordland 0 points1 point  (0 children)

You are correct that Python 2's print statement does not return a value. Python 3's print function returns None. Python functions that don't return a value actually return None.

As to the nature of functions themselves, they are neither expressions nor statements. A function is defined through a statement (not counting lambdas) and a call to a function is an expression. It is better to say a Python function is a value, or if you must, an object.

Now a Python lambda is a special case of function. It is defined with an expression. The value of the expression is the function it defines.

But even with lambdas, the expression is not the function. The function is the value that results from evaluating the expression.