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.
A function call with a string.
Python evaluates the argument.
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
Use print to display a value.
Quotes identify the string.
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
The lowercase name identifies the function.
Parentheses contain the value to pass.
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.
No assignments yet.
OUTPUT
No output yet.
Predict the result, then take the first step.
Text or calculation?
Keep these characters as text.
Evaluate the arithmetic expression.
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: 5Print more than once
Python skips the comment.
The first print ends with a newline.
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")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.