Lesson 2 of 6 · Getting Started · 2 min read · Updated
Your first Python program
Write one line of Python, run it, and see the result on the screen. This is how every Python learner starts.
Understand
A program is a list of instructions for the computer. Python reads your instructions and does what they say.
The first instruction most people learn is print. It shows something on the screen.
print("Hello") makes the word Hello appear on the screen.Use it
Here is your first Python program. It has one line.
print("Hello")
Hello
The word print is the instruction. The brackets hold what to show. The quotes tell Python that Hello is text.
print("Hello")
print("Welcome to Python")
Hello
Welcome to Python
Python runs the lines in order, from the top. Each print shows its text on a new line.
Practice
This code does not work yet. Run it to see what Python says. Then fix it so it prints Hello.
To try it, copy the code into a file on your computer and run it. Your output should match the expected output below.
Expected output
Hello
Need a hint?
- Text needs quotes around it.
- Write
print("Hello").
Show a solution
print("Hello")
Print the word Hello on one line and the word Welcome on the next line.
To try it, copy the code into a file on your computer and run it. Your output should match the expected output below.
Expected output
Hello
Welcome
Need a hint?
- Use two
printlines. - Put each word inside quotes.
Show a solution
print("Hello")
print("Welcome")
Print the number 7. Then, on the next line, print the word seven.
To try it, copy the code into a file on your computer and run it. Your output should match the expected output below.
Expected output
7
seven
Need a hint?
- A number does not need quotes.
- The word seven is text, so it needs quotes.
Show a solution
print(7)
print("seven")
Which line prints the word Hello?
Why it works
print shows whatever you put inside the brackets. It can show text, and it can show numbers.
Write print in small letters. Python sees Print and print as two different words.
Print("Hello")
NameError: name 'Print' is not defined. Did you mean: 'print'?
Python did not know the word Print. It even suggests the right one.
Quotes tell Python that something is text. Without quotes, Python looks for something called Hello and cannot find it. Single quotes work as well as double quotes.
print('Hello')
Hello
Create a free account to save your progress, or sign in.