I am trying the code in the tutorial given here - http://www.vogella.com/tutorials/Python/article.html
He uses python 2.6 and I use 3.3. I don't know if that causes my problem.
My code -
def add(a,b):
return a+b
def addFixedValue(a):
y = 5
return y+a
print add(1,2)
print addFixedValue(1)
Error is -
print add(1,2)
^
SyntaxError: invalid syntax
How do I correct it ?
In Python versions before 3, print was a statement, not a function, so the code as you have it here is correct.
Starting with Python 3, print is now a function, so you need to wrap arguments in parentheses.
print "This is a string"
print("This is a string")
The rationale behind this change is explained at http://legacy.python.org/dev/peps/pep-3105/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With