Write a Simple Program in Python - dummies

Write a Simple Program in Python

By Brendan Scott

Tradition dictates that Hello World! be the first program that you write when you’re learning a new programming language like Python. You’re following in the footsteps of many great programmers when you create this project.

To create your Hello World! program, follow these steps:

  1. Open your Start menu and choose Python (command line).

    You should get a prompt that looks like >>>.

    At the moment, you’re doing everything in interactive mode in the Python interpreter. That’s where the >>> comes in. Python shows you >>> when you’re supposed to type something.

  2. At the prompt, type the following. Use a single quote at the start and the end — it’s beside the Enter key:

    print('Hello World!')
  3. Press the Enter key.

    Python runs the code you typed.

You see the output shown in Figure 1. Congratulations — you’ve written your first program. Welcome to the Python-programmers-in-training club.

If you don’t see what’s in Figure 1, check that you typed in the text from Step 2 exactly as it’s written:

  • Check that the parentheses and single quotes are in the right places.

  • Check that for each opening parenthesis there is a closing parenthesis. (Otherwise, you’re left hanging.

  • Check that for each opening quote there’s a closing quote.

Programming languages have their own grammar and punctuation rules. These rules are the language’s syntax. Humans, can work most stuff out even if perfect not you’re is grammar (See? You figured out what that sentence was trying to say), but Python pretty much freaks out if you get the syntax wrong.