-1

Why, in Python examples on Stack Overflow is there usually no brackets on 'print' statements? Is this because the version used is Python 2?

Meteodeep
  • 3
  • 4
  • https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function – Avihoo Mamka Jul 27 '17 at 08:51
  • Yes, in those cases that there are no brackets it must be python 2 – Ofer Sadan Jul 27 '17 at 08:52
  • You're looking at old Python 2 code that uses the `print` statement. BTW, the `print` function can be enabled in several recent versions of Python 2 via `from __future__ import print_function`. – PM 2Ring Jul 27 '17 at 08:53
  • BTW, `()` are parentheses (singular: parenthesis). Brackets look like this: `[]`, although some people use the terms "square brackets" and "round brackets". – PM 2Ring Jul 27 '17 at 08:56
  • Unfortunately, some people use parentheses with `print` in Python 2 without having done the `__future__` import; so they're passing a tuple (or a single item) to the `print` statement, as discussed in the answers in the linked question. Code that's designed to run on both Python 2 & 3 should _always_ include the `__future__` import, and in fact should use this form to enable Python 3 division handling as well: `from __future__ import print_function, division` – PM 2Ring Jul 27 '17 at 09:03

1 Answers1

1

Print statement in Python 2 was removed in favor of a print function in Python3. Functions are invoked using parentheses - "()", so they are actually needed.