4 ms·
For the specific example of print, then yes. But in general it is not. Another example is if-statements in python: >>> x=if True: File "<stdin>", lin
by bajsejohannes 15y ago
For the specific example of print, then yes. But in general it is not. Another example is if-statements in python:
>>> x=if True:
File "<stdin>", line 1
x=if True:
^
SyntaxError: invalid syntax
whereas in Ruby:
>> x=if true:
?> 5
>> end
=> 5
Other Python statements from the top of my head: for, while, def, import.
My point is that there absolutely are statements that are not expressions in Python. (You can easily tell by trying to assign the return value: x=<statement>).
- kbd 15y agoHeck, assignment itself is a statement. That's why you can't say while x=y: ... (and you'll notice the REPL gives no return value for an assignment). This "Python has no statements" error was one of my biggest annoyances with this article, as Python has a very strong statement vs expression dichotomy.
- deleted 15y ago[deleted]