Skip to content
PythonExamples

LESSON 2 / 5 · 5 MIN

Hello World Program

LET'S MAKE IT CLICK

Hello, world

One line is enough to make Python display a message. Meet print(), the simplest way to see a result.

WATCH THE IDEA
Writeprint("Hello!")

A function call with a string.

RunRead the text

Python evaluates the argument.

SeeHello!

The message appears in the output.

One line connects what you write to what you see.

Move through one idea at a time. Watch, experiment, and check your understanding along the way.

A program in one line

WATCH THE IDEA
Callprint( … )

Use print to display a value.

Pass text"Hello, world!"

Quotes identify the string.

OutputHello, world!

The contents appear without the quotes.

The quotes belong to the code, rather than the displayed message.

print() is a built-in function. Give it a value inside parentheses, and it displays that value. For a message, put the text inside matching quotes.

See the Python code
print("Hello, world!")
Keep in mind

The output is Hello, world! The quotes identify a string in the code; they are not part of this printed message.

Read the punctuation

WATCH THE IDEA
Functionprint

The lowercase name identifies the function.

Argument("Hello")

Parentheses contain the value to pass.

Callprint("Hello")

Matching punctuation completes the instruction.

Each piece of punctuation has a job. Python names are case-sensitive.

The name print tells Python which function to call. Parentheses hold the value you pass to it. Quotes tell Python to treat the characters between them as text.

Single and double quotes can both create strings. Pick matching opening and closing quotes: "Hello" and 'Hello' are both valid. Python names are case-sensitive: Print is a different name from print.

YOUR TURN TO EXPLORE

Give your program something to say.

Edit the message, predict the output, then run the line. Text that looks like code remains part of your message.

example.pyPython
    CURRENT VALUESReady

    No assignments yet.

    OUTPUT

    No output yet.

    Predict the result, then take the first step.

    QUICK CHECK 1 / 2

    What does print("Hello, world!") display?
    You can try again.

    Text or calculation?

    WATCH THE IDEA
    With quotes"2 + 3"

    Keep these characters as text.

    Without quotes2 + 3 → 5

    Evaluate the arithmetic expression.

    CompareText ≠ calculation

    Quotes change what the expression means.

    print("2 + 3") displays 2 + 3; print(2 + 3) displays 5.

    Quotes matter. print("2 + 3") displays the text 2 + 3. Without quotes, print(2 + 3) calculates the sum and displays 5.

    See the Python code
    print("2 + 3")  # output: 2 + 3
    print(2 + 3)    # output: 5

    Print more than once

    WATCH THE IDEA
    Comment# Say hello

    Python skips the comment.

    First callHello

    The first print ends with a newline.

    Second callGoodbye

    The next print appears on its own line.

    Comments explain the code to people; print calls create the output.

    Each ordinary print() call ends with a newline, so two calls usually produce two output lines. A line beginning with # is a comment: it helps readers and is not executed.

    See the Python code
    # Say hello, then goodbye
    print("Hello")
    print("Goodbye")

    QUICK CHECK 2 / 2

    What does print(2 + 3) display?
    You can try again.

    TAKE IT WITH YOU

    What you have learned

    • print() displays the value passed to it.
    • Quotes create text; unquoted arithmetic is calculated.
    • Matching punctuation and letter case matter.

    Answer both quick checks correctly to mark this lesson complete. You can continue at any time.