Reputation: 379
I am reading a Python tutorial and using the Visual Studio 2015 interactive window. The tutorial uses print(b,end=','). But when I type the exact example I always get an error. Here is one such example:
>>> a, b = 0, 1
>>> while b < 1000:
... print(b, end=',')
... a, b = b, a+b
...
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,
Here is what happens using VS2015:
File "<stdin>", line 2
print(b, end=',')
^
SyntaxError: invalid syntax
>>>
I have searched for this problem but nothing mentions it. Then I tried end="," but I get the same error.
Could it be that the tutorial is wrong or that VS is not a perfect Python interpreter?
Upvotes: 0
Views: 24
Reputation: 36574
Your tutorial is showing Python 3 print
syntax, and the error message you are receiving is the message displayed when you attempt to use that syntax under Python 2.x or earlier:
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("foo", end=', ')
File "<stdin>", line 1
print("foo", end=', ')
^
SyntaxError: invalid syntax
You should figure out how in install/run Python 3 in your environment (or find a Python 2.x tutorial, of which there are many).
Upvotes: 1