Why can't I call print function without ()?

Question: I googled the question “why can’t I call the python function without ()?” but the answer was “it is a reference to an object.” Now my question is, Why does python interpreter would think of it as an object. Plus, from what I know if an object (or variable) is not declared before it’s usage then Python throws a name error. So, if python interprets print “Hello!” as an object which is not declared before, why it doesn’t throw a name error? And what does the line, “reference to an object” actually mean?

Joyeta

1 Like

I don’t write Python.

With JavaScript a lot is done under the hood.
Its possible Python is also doing much under the hood that you don’t see. So even if it is technically an object, some things are done for you.

Since I don’t write Python I can only assume, so I found these links for you.
I hope they help :smiley:

oop - What is an Object in Python? - Stack Overflow

3. Data model — Python 3.11.4 documentation

1 Like

It looks like you could call print without () in Python 2:
https://stackoverflow.com/questions/25445439/what-does-syntaxerror-missing-parentheses-in-call-to-print-mean-in-python

In Python 3, unlike Python 2, you can no longer use print without the brackets :slightly_smiling_face:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.