Q1What does the following code display?print("Python", "basics")
Printing and Comments
Start with Python print() for Hello, World! standard output. Cover when to use # vs """ comments and how f-strings embed variable values inside sentences.
Standard Output (print)
When a program displays text on the screen, we call this standard output. In Python, you use a function called print() — whatever value you put inside the parentheses gets displayed on the screen.
Even the classic "Hello, World!" that opens every beginner's book is just a simple program using print() to show that string.
You can wrap strings in either "..." (double quotes) or '...' (single quotes) — both mean the same thing. Just make sure the opening and closing quotes are the same type.
Numbers don't need quotes.
print("Hello, World!") # Hello, World!
print('Hi there') # Hi there
# Numbers don't need quotes
print(123) # 123
# Separate with commas and they're joined with a space
print("Python", "is fun") # Python is fun
Comments
Comments are notes you can leave inside your program. Python ignores them at runtime, so they exist only for humans to read.
Writing them takes a bit of effort, but they help other developers understand what your code is doing.
Everything from # to the end of the line is a comment, and Python ignores it. You can start a comment mid-line too — anything after the # becomes a comment.
Single-line comments (#)
Write a # (hash), and everything from there to the end of the line becomes a comment.
You can place it at the start of a line or partway through a line, which makes it handy for leaving notes inside your code.
Multi-line comments ("""...""")
When you want an explanation that spans multiple lines, wrap it with """ (three double quotes) on both sides and everything inside is treated as a comment.
Strictly speaking it's a "multi-line string," but if you don't assign it to anything, it effectively behaves the same as a comment.
# This is a single-line comment
print("This runs") # You can also add comments at the end of a line
"""
You can use this
as a comment
spanning multiple lines
"""
print("This runs too")
Comments can also temporarily disable code
Add a # at the start of a line you don't want to run, and that line gets skipped. This is called commenting out, and it's handy when you're debugging or experimenting.
Embedding values with f-strings
So far you've only printed fixed strings. In real code, though, you'll often want to mix a variable's value into your text — something like "Hello, {Alice}!" (we'll cover variables on the next page).
That's what f-strings are for. Just add an f in front of the string and write {variable_name}, and the variable's value gets dropped in right there.
name = "Alice"
age = 18
# f-string: put the variable name inside {}
print(f"My name is {name}") # My name is Alice
print(f"I'm {name}, {age} years old") # I'm Alice, 18 years old
# You can write expressions inside {} too
print(f"Next year I'll be {age + 1}") # Next year I'll be 19
# For reference: the older .format() style does the same thing
print("My name is {}".format(name)) # My name is Alice
f-strings are available from Python 3.6 onwards and are the current standard way to do this.
The older "...{}...".format(value) style was the standard way to do this, but if you're learning today, just stick with f-strings.
In this article you've picked up Python's first essential tools — printing to the screen with print(), writing comments with # and """...""", and embedding variables into strings with f-strings.
With these, you can already write basic programs that assemble values and show them on the screen. In the next article, we'll cover variables — the boxes that hold your values.
Knowledge Check
Answer each question one by one.
Q2Which symbol is used to write a single-line comment in Python?
Q3What does the following code output?name = "Alice"
print(f"Hi, {name}!")