ShareYourGroupShareYourGroupPython

Lesson 1 of 21 · about 5 minutes with the exercises

Your first Python program

Python is a programming language. You write instructions in plain text, and the computer follows them one line at a time, from top to bottom. People use Python to automate boring work, to study data, to build websites and to teach programming in schools and colleges. It is a good first language because the code reads almost like English and you need very little of it to make something happen.

This lesson gets one small program running. Do not skip it, even if it looks too easy. Every later lesson assumes you can type a program, run it and read what comes back.

Three ways to run Python

  1. On your computer. Install Python from the official website, python.org. On Windows, tick the box that adds Python to PATH when the installer asks. Then open the program called IDLE, which comes with Python. Choose File, New File, type your code, save it with a name ending in .py, and press F5 to run it.
  2. In a browser. Many websites give you a box to type Python and a Run button. Nothing is installed. This is fine for the first few weeks of learning.
  3. On a phone. There are free apps that run Python on Android and iPhone. A phone keyboard is slow for long programs, but it is enough to try every example on this site.

Our set-up page walks through each of these in more detail.

The first program

Type this exactly as shown and run it.

print("Hello, world")

Output

Hello, world

The grey box under the code shows what Python printed. If you see the same words on your screen, your set-up works.

Here is what each part does:

More than one line

A program is usually many lines. Python runs them in order.

print("My name is Asha.")
print("I am learning Python.")
print(2 + 3)

Output

My name is Asha.
I am learning Python.
5

Look at the third line. There are no quotation marks, so Python treats 2 + 3 as a sum and prints the answer. With quotation marks it would print the characters as they are:

print("2 + 3")

Output

2 + 3

This difference between text and numbers matters in almost every program you will write.

When something goes wrong

Everyone makes typing mistakes. Python stops and tells you where the problem is. Here the closing quotation mark is missing.

print("Hello, world)

What Python says

  File "example.py", line 1
    print("Hello, world)
          ^
SyntaxError: unterminated string literal (detected at line 1)

Read the last line first. It names the kind of mistake, here a SyntaxError, which means Python could not understand the line. The lines above point at the place. An error message is not a scolding. It is the fastest help you will get, so make a habit of reading it slowly. Our error pages explain the common ones.

Rules to remember

Try it yourself

Exercise 1. Print your own name on one line and your city on the next line.

Show one answer
print("Ravi Kumar")
print("Ludhiana")

Output

Ravi Kumar
Ludhiana

Exercise 2. Make Python work out 365 multiplied by 24 and print the answer. The multiplication sign in Python is the star.

Show one answer
print(365 * 24)

Output

8760

Exercise 3. Print the sentence Python is fun three times using three lines of code.

Show one answer
print("Python is fun")
print("Python is fun")
print("Python is fun")

Output

Python is fun
Python is fun
Python is fun

Examples on this page were run with Python 3.14 on 12 November 2026. The output shown is the real output.

This is an independent learning site. It is not connected with or approved by the Python Software Foundation. "Python" is a trademark of the Python Software Foundation and is used here only to name the language.