17 print command with or without ( )


I passed nr 17 but I had to use the print command in the python 2 way. I tried it first with the parenthesis's like so:
print (key, my_dict[key])
But that gave an error message with the right info between parenthesis's. I should have passed.
print key, my_dict[key]
Let me pass.

I thought we were using python 3. But this is 2 (if I am not mistaken). Am I correct?



as far as I know, we are using python 2.7 here, but the parenthesis shouldn't be an issue at all in 2.7

The only thing is that it prints the () as well as the string in it.


Thanks for pointing it out to me. Now I know what to expect (python 2.7) and what not (python 3).


You were printing a tuple, yeah.

You can disable the print statement to get access to the function by the same name:

from __future__ import print_function

If you want to write code compatible with both versions, that's the way to go, or if you just prefer the function over the statement.

Exercises that expect output might actually not like it if you do that though, don't know.

Python version can be viewed with:

import sys
print sys.version

As for which version is "better" to learn - doesn't really matter, same language. Yes there are differences but at the same time both are actively used (new projects made in Python 3, stable code bases still using 2.7) so you should pretty much just be able to use either, google is your friend as with all other errors and issues and what not.


It seems I have a lot to learn. :slightly_smiling:
Is the first command to make python 2 to work like 3?

It must be hard to convert python 2 to python 3. Or it must be by the saying "If it ain't broken don't fix it".