First Things First

Posted by Neville on September 14, 2016 under How To, Python, Resources, Training, Uncategorized | Comments are off for this article

Let’s Begin To Code!

For this step in the coding experience we will be first of all using the shell, and then move into using an IDE (in our case IDLE). If you have not yet installed python, now might be that time!

Our First Output

The conventional first step for almost all courses in coding and programming is to get the computer to print out the simple sentence “Hello World”. Well here’s how it’s done in python. (Well, it’s just one way to do that!).

Let’s get started!

Open up the python shell (or open Idle and use the shell component). You should be able to see the prompt (>>>), and that is where you type the following: print(“Hello World”) and then press the enter key.

If you have done that successfully, the next line of the shell will show Hello World, and then the prompt is displayed on the line below. If, however, you see an error message there is something not quite right with what you typed in. Hopefully the message will give you a clue about what the problem is.

A note about the print command:print command

print, in lower case, is a reserved word in python that is used to output the contents of what is between the parens, or brackets. That output in this case goes to the shell. In this example the contents between the parens is a series of characters enclosed in quotes. It is so much easier to call this a string. Strings in python can be enclosed in either single quotes (‘like this’) or double quotes (“or this”). Double quotes are good when you need to use an apostrophe in a string (“isn’t that handy”).

Experiment with the print command in the shell. Try it with numbers. eg print(4 + 8) or print(3 + 2.5). Note that no quotes are required for numbers when printing. What happens if you forget the quotes for a string? Try it and see if you can work it out.


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Comments are closed.