Multiplying Strings

10 Oct, 2017

Robin L writes (excerpted):

I am trying to teach myself how to code and thought this was a good place to begin. I am having trouble with the "multiplying strings" section. I don't know anyone else who codes so I am hoping that you are still available at this email. This is the part about printing a letter in the shell. For some reason when I run mine the "print()" keeps actually printing "()".

Can you please help me figure out what I am doing wrong?

There's a pretty major difference between printing with older versions of Python (Python2.7 and earlier) and newer versions (Python3 and later). In Python2, print is a statement, which means this works fine:

print "hi there"

If you try that in Python3, you'll get an error:

print "hi there"
  File "<stdin>", line 1
    print "hi there"
               ^
SyntaxError: Missing parentheses in call to 'print'

That's because print in Python3 is a function not a statement.

Why does that make a difference? In Python2, this code...

print()

...is a print statement followed by an empty tuple. You're effectively telling Python to "print this empty tuple", and by quirk of the way the print statement works, you get (). The exact same code in Python3 is a function name (print) followed by an open bracket, no parameters, and a closing bracket. You're providing no parameters and the function prints nothing as a consequence. And that, basically, is the difference.

Cutting a long story short - all you're doing wrong is running an older version of Python. Check chapter one, and follow the instructions to install Python3, and the code will work as you expect.


Python 3.5 beta issue on Windows

21 Aug, 2015

Tony writes:

I have installed Python 3.5.0b3, and when I tried to make the shortcut, it looked very different from the book's examples and I did not get the toolbar with "File", "Edit", "Options", etc. on the top. Please tell me how to correctly complete the installation process. Thank you, and I hope to hear back.

I'm not sure exactly what error you're getting, but I would suggest that while learning programming, you should probably use the latest release version of Python, rather than the beta. So at time of writing, that's version 3.4.3.

I do know of one problem with 3.5, where you need to move the DLL found in directory c:\Python35\DLLs\Microsoft.VC140.CRT, up one level (to directory c:\Python35\DLLs), in order to get tkinter working -- which I guess could be part of your problem (as detailed here: https://bugs.python.org/issue24847).

So that's simply moving the file here:

microsoft.vc140.crt file - original location

to here:

microsoft.vc140.crt file - new location

NOTE: this is no longer required for the release version of 3.5 (it was only necessary for the beta versions)