Errors and Experimentation

Part 4: Learning Through Mistakes and Exploration

Introduction to common errors in Python and basic experimentation strategies.

Common Errors

Errors and bugs are a normal part of learning and programming. Consider them hints that something needs adjusting, not failures. Experimentation is about testing your ideas safely with small, simple steps. Python errors usually come with a message that describes what went wrong. Below are the most common types beginners see:

SyntaxError

A SyntaxError happens when Python doesn’t understand the code structure (missing a parenthesis, colon, etc.).

NameError

A NameError occurs when you try to use something that hasn’t been defined yet.

TypeError and ValueError

TypeError means the wrong type of object was used. ValueError means the type was right but the value didn’t make sense.

IndexError

IndexError means you asked for a position that doesn’t exist.

File Errors

FileNotFoundError and PermissionError happen when files or paths don’t exist or can’t be accessed. Relative vs. absolute paths, and read/write permissions, are often culprits with these.

NoneBig Picture Errors

Sometimes errors come from bigger issues: the Python version you’re using, missing packages, or environment setup. This browser based tutorial should avoid any of those for now.

But be aware, those errors can cause headaches.

Debugging is most effective when structured, check out On the Shoulders of Giants for more general troubleshooting tips.

Experimentation

Experimentation means testing your ideas step-by-step. Debugging works a lot like scientific research. Instead of guessing randomly, treat each step as a test:

  • Form a hypothesis: “Maybe the list is empty.”

  • Test it: print(len(my_list))

  • Observe: Check if the result matches your idea.

  • Revise: If not, try a new explanation.

Issue Wild Guess Testable Hypothesis Test Syntax/Process
Can’t load a file I deleted it The file still exists, just in the wrong place Check Finder/Explorer, confirm relative vs. absolute path
I can’t remember all this syntax I cannot code Other learners look things up too Search docs, Stack Overflow, or examples — even experts do this
I keep getting errors This will never run, I should give up Repeated errors show where my understanding is growing Review progress, look for recurring issues, adjust and retry
Loop runs forever Python is broken My loop condition never becomes false Print the variable in the loop, check where/if it changes
Unexpected output Computer is wrong The variable has a different type or value than I expect Use type(x), print(x), or len(x) to inspect
Function gives error Functions are too advanced for me I passed the wrong number/type of arguments Check the function definition and call, print the inputs

Check Types and Values

Use len() to Check Size

Comment and Change Slowly

Use # to comment out lines temporarily. Make one change at a time and re-run to see the effect.

NoneUse f-Strings for Context Printing

Instead of guessing what a printed value means, f-strings let you add context directly in the output. They are one of the easiest ways to add clarity to print statements and much more.

  • Errors are hints, not failures.
  • Experiment with simple tools (type(), print(), len()).
  • More advanced error topics like environments, packages, and permissions are covered elsewhere.

Next Steps

Congrats on finishing the Try Python series.

Looking for deeper content? Check out notebook based tutorials in Explore Data