Your First Program: Print, and Running Code

Python for Absolute Beginners · Lesson 3

What you’ll learn

1 / 14

Two ways to run Python

2 / 14

In the shell: your first line

print("Hello, world!")

Output:
Hello, world!

print means “show this on the screen.” The words inside the quotes are called a string — text, as opposed to a number.

3 / 14

The first common mistake

print(Hello)

Error:
NameError: name 'Hello' is not defined

Without quotes, Python thinks Hello is a name, not text. The error means: you used the name Hello, but I have no value stored under that name. Text needs quotes; names do not.

4 / 14

Comments: notes that do not run

5 / 14

A comment in code

# This line is a note. Python skips it completely.
print("Comments help future you remember why you wrote this.")

Output:
Comments help future you remember why you wrote this.

Only the print line runs.

6 / 14

Your first program file

7 / 14

hello.py

# My first program
print("Hello, world!")
print("My name is Sam.")
print(2 + 3)

Output:
Hello, world!
My name is Sam.
5

Notice the third line: 2 + 3 has no quotes, because it is arithmetic, not text. Python works it out and prints 5.

8 / 14

Text in quotes, numbers bare

9 / 14

The two most common first-day mistakes

10 / 14

Hands-on exercise

11 / 14

Key takeaways

12 / 14

Take the quiz

Take the Lesson 3 quiz — 5 quick questions to check what you learned.

13 / 14

Next lesson

Variables: Storing Things

14 / 14

Press play on any slide and the lesson plays on by itself from there. You can still click Next or click a slide to move on.