For those of you interested in learning Python 3, I’m going to start revisiting old blog posts, updating them for Python 3. They might, but probably won’t, be repeating the same order as the original. Python 3 posts will start with a 3 (in case you hadn’t worked out the 3: at the start of this posts’ title). To do these posts I’m assuming that you’ve:
- Installed a version of Python starting with 3 (if you have a version starting with 2, start here). If you haven’t installed it, follow the instructions on the Getting Started page.
- Managed to open Python (command line). You can also use the IDLE editor (and you’ll get onto that later anyways).
For some reason, lost to the mists of time, the first program you write in any language is supposed to be a program, called “Hello World”, that gets the computer to say “hello world”. So here it is. Open up your Python prompt. You should see something like this:
>>>
That thing’s the Python prompt. Type everything after the >>> in the first line here:
>>> print('hello world!') hello world! >>>
When you press the Enter* button at the end of the first line, “hello world!” appears on the next line. Make sure that you type:
print('hello world!')
in exactly. That is, (don’t type >>>) but make sure you include the (, ‘, ‘ and ). If you leave any of them out, it won’t work (try it).
Congratulations, you’re now a programmer (in training).
* If you are on a Mac, think “Return Button” whenever I say Enter button.