Himanshu SharmaSoftware engineer
Let’s talk

Python Tutorial · Lesson 3 of 70

Your first Python program: print and run

Write and run your first Python program with print(), learn what a statement is, how strings and quotes work, and how to read your first error messages.

10 minGetting startedUpdated 14 November 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonWrite a short program that prints text and numbers with print(), run it, and understand a simple error message.

After this lesson you can write a tiny Python program, run it and read the result. It is short on purpose. The skill you need is the loop of write, run and look, and you will use it for the rest of your programming life.

Hello, shop

The traditional first program prints a greeting. Here is one with a small twist:

python
print("Welcome to the Corner Shop")
result
Welcome to the Corner Shop

print is a built-in function. It takes whatever you put between the brackets and shows it on the screen. The thing inside the brackets is called an argument. Here the argument is some text.

Text in Python is called a string. A string is written inside quotes so that Python can tell the difference between text and instructions. Without the quotes, Python would try to treat Welcome as an instruction and complain.

You can use double quotes or single quotes, as long as you start and end with the same kind:

python
print('Open every day')
print("Open every day")
result
Open every day
Open every day

Both lines do exactly the same thing.

Numbers and calculations

You can print numbers too, and numbers do not need quotes:

python
print(42)
print(3 + 4)
print(12 * 5)
result
42
7
60

The last two lines show that Python will calculate for you. 3 + 4 is not text, so Python works it out and prints the answer. Compare that with quotes around it:

python
print("3 + 4")
result
3 + 4

Now it is a string, and Python prints it exactly as written. Quotes mean "this is text, leave it alone". No quotes mean "this is code, work it out".

Printing several things at once

You can give print more than one argument, separated by commas. Python puts a space between them:

python
print("Items sold today:", 18)
print("Total in rupees:", 18 * 45)
result
Items sold today: 18
Total in rupees: 810

Each call to print starts a new line, so these two statements appear on two lines of output. A statement is one complete instruction. Python runs your statements from the top of the file to the bottom, one after another.

Running the program

Save any of the examples above in a file, for example hello.py, then run it from a terminal opened in the folder that holds the file:

bash
python3 hello.py

On Windows you may need python hello.py or py hello.py instead. The next lesson covers running code in detail, including an interactive mode.

Your first error

Everyone writes mistakes, and Python reports them. Seeing errors early is useful, because they stop being scary. Here is a string whose quote was never closed:

python
print("Welcome to the shop)
result
SyntaxError: EOL while scanning string literal

The last line of an error message is the most helpful one. It names the kind of error, here a SyntaxError, and gives a short reason. A syntax error means the code is not written in a form Python understands. The lines above it show roughly where Python gave up.

Another common mistake is a misspelled name:

python
Print("Hello")
result
NameError: name 'Print' is not defined

Python is case sensitive, so Print and print are different names. This time the error is a NameError, meaning Python does not know any such name.

Reading a program like Python does

It helps to imagine yourself as the interpreter. You begin at the first line, do exactly what it says, then move to the next. You never skip ahead, and you never guess what the author meant. If a line is wrong, you stop and report the problem.

This tells you something useful about debugging. When a program misbehaves, walk through it line by line with a pencil and note what each statement does. The place where your picture and the real output stop agreeing is usually where the bug lives. Beginners often try to understand a whole program at once, which is far harder than following it one step at a time.

It also explains why blank lines and spacing between statements do not change what happens. Python ignores blank lines, so you are free to use them to group related steps and make the file easier to read.

Common mistakes

  • Forgetting a closing quote or bracket. Every opening quote and every opening bracket needs its partner.
  • Using capital letters in print. It must be print in lowercase.
  • Leaving out the brackets. In Python 3, print is a function and needs them.
  • Using curly or "smart" quotes. If you copy code from a word processor, quotes may be curly. Python only accepts the plain straight kind.
  • Starting a line with spaces by accident. Leading spaces carry meaning in Python, so a stray one can cause an error.

Exercise

Write a program that prints three lines: the name of an imaginary shop, a line that says how many customers came today (use the number 25), and the amount they spent in total, which is 25 customers times 40 each, calculated by Python and not by you.

Show one possible answer
python
print("Corner Shop")
print("Customers today:", 25)
print("Total spent:", 25 * 40)
result
Corner Shop
Customers today: 25
Total spent: 1000

The last line lets Python do the multiplication, so if a number changes you only edit that number. Notice that the text has quotes and the calculation does not.

Next: more ways to run Python code.

Key points

  • print() shows text, numbers and other values on the screen.
  • Text in quotes is a string. Single quotes and double quotes both work, but you must close what you open.
  • Python runs statements from top to bottom, one at a time.
  • Error messages name the problem and the line. Read the last line first.

Check yourself

1. What does print("Hello") do?
2. Which line is a valid Python statement?
3. In what order does Python run the lines of a simple program?
4. What does print(3 + 4) show?
5. Where should you look first in an error message?