-1

I am playing with the string interpolation and I keep getting the following and don't understand why I keep getting invalid syntax

>>> import time
>>> today = time.strftime("%A")
>>> print "Today is %s." % today
File "<ipython-input-3-c488ebb957ac>", line 1
print "Today is %s." % today
                   ^
SyntaxError: invalid syntax
user2757400
  • 45
  • 1
  • 8

2 Answers2

1

In Python 3 — which you must be using here considering your code is valid Python 2 —, print is a function, and must therefore be called with parentheses:

print("Today is %s." % today)

Note that if you're running Python 2, then you could have enabled this behavior with the following command (did you do any interpreter customizations?):

from __future__ import print_function 

Note that the Python version you're running is displayed when you startup the interpreter. You can also run python --version from your command line to see it.

Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
0

Perhaps you're inadvertently invoking a Python3 interpreter. Try print("Today is %s." % today). (print() as a function rather than the old print as a statement.

Jim Dennis
  • 17,054
  • 13
  • 68
  • 116