CodeStride
Getting Started

Your first program in Python

Topic 1 of 58 · 5 minFree lesson

A program is a list of instructions for a computer. The computer follows them one line at a time, from top to bottom.

Python is a language for writing those instructions. It is popular because it reads a lot like English. That makes it a great first language.

Showing a message

Your first instruction is print(). It shows whatever you put inside the brackets.

Example 1
print("Hello, world!")
Hello, world!

The text inside the quotes is called a string. You'll learn much more about strings soon. For now, remember that text needs quotes around it. You can use double quotes " or single quotes '. Both work the same way.

More than one line

Each print() shows its message on a new line. Python runs the lines in order, top to bottom.

Example 2
print("Good morning!")print("Let's learn Python.")print("One step at a time.")
Good morning!Let's learn Python.One step at a time.

Printing numbers

Numbers don't need quotes. Python can even do the math for you before it prints.

Example 3
print(7)print(2 + 3)
75

Notice the difference quotes make. With quotes, Python prints the text exactly as you typed it. Without quotes, it works out the answer.

Example 4
print("2 + 3")print(2 + 3)
2 + 35
Common mistakeForgetting the quotes around text. Python then thinks your word is the name of something it should know, and stops with a NameError.
Example 5
print(Hello)
NameError: name 'Hello' is not defined

Put quotes around the text and it works: print("Hello").

TipPython cares about capital letters. print works, but Print and PRINT do not. Always write print in lowercase.

Try it yourself

Run the code in the editor and answer 8 practice questions on your first program. It's free, you only need an account.