Getting Started with Python · Lesson 4

Your First Program with Print

print() is a built-in function that converts supplied objects to a readable text representation and writes that text to an output stream, normally the console.

ConceptWorked examplePracticeKnowledge check
Textbook walkthrough

What Your First Program with Print actually means

print() is a built-in function that converts supplied objects to a readable text representation and writes that text to an output stream, normally the console. It is one of the simplest ways to make program state visible while learning and debugging.

This foundation matters because Python code can be written in several interfaces but is ultimately executed by an interpreter with concrete syntax, runtime state and error behaviour. Understanding Your First Program with Print makes later debugging and project execution much less mysterious.

Deeper walkthrough

Read Your First Program with Print as a mechanism, not a recipe

Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Evaluate each argument passed to print(). Stage 2: Convert values to text using their string representation. Stage 3: Separate multiple arguments with sep (a space by default). Final checkpoint: Write to standard output unless a different file-like target is supplied.

Mechanism

Follow the transformation

Evaluate each argument passed to print().

Convert values to text using their string representation.

Separate multiple arguments with sep (a space by default).

Evidence

Know what would convince you

  • Run the operation on a tiny literal input and write the expected type/value before executing it.
  • Inspect the relevant object state before and after the operation, especially when mutable objects are involved.
Useful distinctionprint(value): Displays a value for the user or developer.
How it works

Trace the mechanism step by step

  1. Evaluate each argument passed to print().
  2. Convert values to text using their string representation.
  3. Separate multiple arguments with sep (a space by default).
  4. Terminate with end (a newline by default).
  5. Write to standard output unless a different file-like target is supplied.
Worked demonstration

Make the concept concrete

Demonstration

Python example

# Step 1 — Compute the right-hand expression and store its result in `name` for the next step.
name = "Amina"
# Step 2 — Compute the right-hand expression and store its result in `score` for the next step.
score = 87
# Step 3 — Display the current value explicitly so the result/state can be inspected during execution.
print("Learner:", name)
# Step 4 — Display the current value explicitly so the result/state can be inspected during execution.
print(f"Score: {score}%")
# Step 5 — Display the current value explicitly so the result/state can be inspected during execution.
print("A", "B", "C", sep=" | ", end=".\n")
Expected / illustrative result
Learner: Amina
Score: 87%
A | B | C.
Interpret the result.

For Your First Program with Print, connect the displayed result to the specific input and mechanism above; independently verify one value/state change rather than treating successful execution as proof.

Distinctions & related ideas

Know what this is — and what it is not

print(value)Displays a value for the user or developer.
return valueSends a value back to the caller of a function; it does not automatically display it.
loggingRecords structured diagnostic messages with severity levels and configurable destinations.
Use deliberately

When it is appropriate

Use Your First Program with Print when the program genuinely needs this language behaviour and you can state the input object, resulting value/state and expected failure behaviour.

Boundary conditions

When to stop or reconsider

Choose a clearer built-in, data structure or control-flow pattern when it expresses the intent more directly; stop if implicit conversion, mutation or hidden state makes the behaviour hard to reason about.

Common mistakes

Failure modes to recognise

  • Applying the operation to an incompatible type or assuming Python will silently coerce values the way you intended.
  • Confusing a returned value with an in-place mutation or other side effect.
  • Testing only the happy path and missing empty, boundary or invalid inputs.
Verification

How to check the result

  • Run the operation on a tiny literal input and write the expected type/value before executing it.
  • Inspect the relevant object state before and after the operation, especially when mutable objects are involved.
  • Try one boundary or invalid input and confirm that the returned value or exception matches the intended contract.
Hands-on practice

Demonstrate understanding

Try this:

Build a tiny, inspectable example of Your First Program with Print. First evaluate each argument passed to print(). Then convert values to text using their string representation. Write the expected result before running it, and explain one condition that would make the result misleading or invalid.

Use the smallest values that expose the rule. Write the expected value and type first, then compare Python’s actual state/output with that prediction.
Knowledge check

Check reasoning, not memorisation

Before trusting a result from Your First Program with Print, which check provides the strongest evidence that you understand and applied it correctly?

Quick reference

Keep the important distinctions visible

Step 1Evaluate each argument passed to print().
Step 2Convert values to text using their string representation.
Step 3Separate multiple arguments with sep (a space by default).
Step 4Terminate with end (a newline by default).
Lesson summary

What to remember

  • print() is a built-in function that converts supplied objects to a readable text representation and writes that text to an output stream, normally the console. It is one of the simplest ways to make program state visible while learning and debugging.
  • Evaluate each argument passed to print().
  • Applying the operation to an incompatible type or assuming Python will silently coerce values the way you intended.
  • Run the operation on a tiny literal input and write the expected type/value before executing it.