Skip main navigation

Write your first Python program

Write your first computer program - the classic Hello World. In this article, Martin O'Hanlon guides you through the steps required.

The start of every new programming experience is creating a “Hello World” program. It’s one of the simplest programs you can create, and it will put the message “hello world” on the screen.

Programmers will often create a “Hello World” program to test that everything is working before they start anything new, and this is what you are going to do.

There are separate instructions below for the Mu and Trinket IDEs – follow the instruction for the IDE you have chosen, you don’t need to complete both.

Mu

This is an additional video, hosted on YouTube.

  • Create a new program in Mu by clicking the New icon.

An image of the Mu IDE, with the new button on the top left highlighted

  • Type the following code into the editor:
print("hello world")
  • Click Save to save the program.

  • Enter the file name helloworld and click the Save button.

An image of the Mu IDE, with the Save button at the top highlighted, and a save file dialog box open with the Save button also hightlighted.

  • Click Run to run the program.

An image of the Mu IDE, with the Run button at the top highlighted

The message “hello world” should appear in the REPL.

An image of the Mu IDE, with the helloworld.py program shown in the editor, and the message "hello world" shown in the REPL

Any errors in your program will appear in the REPL with a description.

An image of the Mu IDE, with the text "Print("hello world")" in the editor, and the REPL showing the error message "NameError: name 'Print' is not defined"

If you get an error, look over the code carefully to make sure everything is correct.

There are a few important points to make which might help if you experience an error:

  • The code is case-sensitive, so capital letters are important – print is not the same as Print
  • Text, such as a message to be printed, needs to be between speech marks so be sure to put the "hello world" message in between " "
  • print expects the message to be in between parentheses (brackets)

  • If you need to change your program, stop it and run it again by clicking Stop and then Run.

Trinket

This is an additional video, hosted on YouTube.

  • Sign up for Trinket and log into your account.

  • Create a new Python project by clicking New Trinket > Python.

New Trinket>Python selected “>

  • Type the following code into the editor:
print("hello world")
  • Save your project by giving it the name “helloworld” and clicking Save.

A trinket webpage, with the filename "helloworld" and the "Save" button highlighted

  • Click the Run icon to run your program.

The message “hello world” should appear in the REPL.

A trinket webpage, with the "Run" symbol button highlighted above the editor, the code "print("hello world")" in the editor, and the resulting text "hello world" visible in the REPL

Any errors in your program will appear in a red box with a description at the bottom of the screen.

A trinket webpage with the line of text "Print("hello world")" highlighted in red, with a red box below the editor reading "NameError: 'Print' is not defined on line 1 in main.py"

If you get an error, look over the code carefully to make sure everything is correct.

There are a few important points to make which might help if you experience an error:

  • The code is case-sensitive so capital letters are important – print is not the same as Print
  • Text, such as messages to be printed, needs to be between speech marks so be sure to put the "hello world" message in between " "
  • print expects the message to be in between parentheses (brackets)

Tip: new learners often think that the command print will make the text appear on paper from the printer rather than on the screen.

This article is from the free online

Programming 101: An Introduction to Python for Educators

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education