Skip to main content

2.3) My first Python command

Now let’s write our first Python command.
It is a tradition in computing that the first program you write is one that prints the line "Hello World!". Let's follow this tradition and get you started with your first program.
At the interpreter prompt (i.e. after the three arrows), type 'print "Hello, World!" '. Don’t paste the text, you’ll learn much more if you type everything in. Don’t start lines with a space. It will look like this:
[code lang="python"]
>>> print "Hello, World!"
Hello, World!
>>>
[/code]
Well done, you wrote your first command! This was pretty straightforward. You asked Python to print the sentence "Hello, World!" and you got the result underneath. After that, you get a new prompt ready for you to enter your next command. This time enter '2+3' and press the Return/Enter key on your keyboard. Remember, don’t start a line with a space.
[code lang="python"]
>>> 2+3

[/code]
For the curious: you will have noticed here that all you needed to do to run your one line program was to press Return/Enter. There was no compilation step (like you might have in fortran or C++) and the answer appeared immediately. We call Python an interpreted language like R and Matlab, while fortran and C++ are compiled languages.