Code works in lesson but exact code pasted to compiler does not


Link to lesson:

I am not sure why this is happening or if it matters in the end. This bit of code works in the lesson and allows me to move forward:

from datetime import datetime
now =

print '%s/%s/%s' % (now.month,, now.year)

However that same bit of code gives an error in the shell as well as PyCharm:

**print '%s/%s/%s' % (now.month,, now.year)**

** ^**
SyntaxError: invalid syntax

Process finished with exit code 1

It works fine if I print each one in a line by itself but not when I use %. As I do the little projects after lesson chunks I also work on them in PyCharm. This is the first time where this has happened to me. I have looked at this for a while, is there something I am missing?

Thank you very much for your help.


This is Python 2.*. Python 3.* requires parenthesis around the expression, and has a new .format() function for string formatting. Try adding parentheses, and see if it lets the old string formatting still play out.

print ( '...' )


Try it by using

print("{0}/{1}/{2}".format(now.month,, now.year))

And with a google search
== discussions / opinions ==
python pycharm print statement
python print statement vs print function


Thanks... sorry for the dumb question. What is even more dumb is I have been doing these lessons thinking I have been on Python 3 haha...

Thank you, I will try to do better research before posting again.