Skip to course content
Free course

Python Foundations / Module 1 / Getting Help and Reading Errors

Module 1 lesson

Getting Help and Reading Errors

Unit ID: M01-U06 Estimated active time: 20-25 minutes

You are not expected to memorise everything

Programming is not a memory test. Skilled programmers regularly inspect documentation, read error messages, and test small examples.

Python includes a built-in help() function. Try:

help(print)

The result contains more detail than you need today. Look for three useful parts:

  • the name of the function;
  • the values it can receive; and
  • the plain-language description of what it does.

You do not need to understand every symbol in the function signature yet.

Inspect a short description

Many Python objects contain a docstring: documentation stored with the object.

print(print.__doc__)

The output describes print(). The double underscores are part of the special attribute name. You do not need to memorise it; use help() as the normal starting point.

Read an error from the bottom

Run this deliberate mistake:

course = "Python Foundations"
print(corse)

The second line uses corse, but the created name is course. Python reports a NameError.

A notebook traceback may contain several lines. For a simple error, begin at the bottom:

  1. Error type: NameError.
  2. Message: a name is not defined.
  3. Location: the line containing print(corse).

Now compare the two names carefully. Correct the spelling and rerun the cell.

Do not erase the evidence too quickly

When code fails, pause before replacing the whole program.

Use this routine:

  1. Read the last line of the error.
  2. Find the highlighted or reported line.
  3. State what Python expected and what it received.
  4. Change one likely cause.
  5. Rerun the smallest relevant cell.
  6. Restart and run all when the repair is complete.

Changing many lines at once makes it hard to know which change fixed the problem.

A syntax error

Run this code:

print("Welcome to Python)

One quotation mark is missing. Python cannot correctly parse the instruction, so it reports a SyntaxError.

Correct version:

print("Welcome to Python")

The error location is a clue, not always a perfect diagnosis. Check the reported line and the line just before it.

A type-related error preview

print("Total: " + 25)

This fails because the code tries to join text and a number using +. We will study types in Module 2. For now, use:

print("Total:", 25)

The comma lets print() display the two values safely.

Practice: repair three mistakes

learner_name = "Asha"
print(learner)
print("Start learning Python)
daily_total = 450
print("Daily total: " + daily_total)

For each example, record:

  • the error type;
  • the line that needs attention;
  • the smallest correction; and
  • the successful output after repair.

Takeaway

Errors are evidence about the program's current state. Read the error type, message, and location before changing code. Use help() when you need to inspect how a Python tool is meant to work. Next, we will combine these habits into a reproducible notebook routine.