The print used to be a statement in Python 2, but now it became a function that requires parenthesis in Python 3.
print
Is there anyway to suppress these parenthesis in Python 3? Maybe by re-defining the print function?
So, instead of
print ("Hello stack over flowers")
I could type:
print "Hello stack over flowers"
In Python 3, print is a function and requires parentheses. However, if you really want to use the old syntax without parentheses, you can achieve it by adding the following import at the beginning of your script:
from __future__ import print_function
This import allows you to use the print function with the old Python 2 syntax in Python 3. Keep in mind that this is more of a workaround and might make your code less readable, so it’s generally recommended to adapt to the new syntax.
Here’s an example:
from __future__ import print_function print("Hello stack over flowers")
With this import, you can still use print without parentheses in Python 3, but it’s important to note that this is a feature provided for transition purposes and might not be present in future Python versions.