While working on a Python project, I realized that during my editing I had left a string floating around in the middle of my code and it didn't generate an error. For example, these few lines execute just fine:
print("Starting")
"This string does nothing"
["Neither does", "this list"]
print("Done")
Output:
Starting
Done
It seems to me that since there are no statements or function calls, those should generate syntax errors. Why is there no exception raised, and is there some use for a construct like this?
print('Done')
is also an expression. It even returnsNone
(produces a value). Should it be a syntax error too? How can I distinguish that call fromtuple(['some', 'list'])
, wheretuple()
is a type and produces an object? As far as Python syntax is concerned calling a type to produce an object and calling a function are the exact same thing, so you cannot distinguish function calls from other expressions.