Debugging

Your code has a bug in it. What now?

8 articles · 51 min read
5 screencasts · 18 min watch
01
SyntaxError: invalid syntax
14 min read

Python's "invalid syntax" error message comes up often, especially when you're first learning Python. What usually causes this error and how can you fix it?

Read
Read
02
Fixing TypeError: can only concatenate str (not "int") to str
5 min read

Python crashed with the error TypeError: can only concatenate str (not "int") to str. Essentially Python's saying you've used + between a string and a number and it's unhappy about it. Let's talk about how to fix this issue and how to avoid it more generally.

Read
Read
03
breakpoint: debugging
6 min read Screencast available

Need to troubleshoot an error in your Python code? Use Python's built-in breakpoint function to launch the Python debugger.

Read
Read
04
The features of Python's help() function
10 min read

Python's help() function accepts more than functions, modules, and objects. The help() function can lookup help for symbols, keywords, and topics!

Read
Read
05
Inspecting objects
5 min read Screencast available

I rely on 4 functions for inspecting Python objects: type, help, dir, and vars.

Read
Read
06
Debugging with f-strings
4 min read Screencast available

If you're debugging Python code with print calls, consider using f-strings with self-documenting expressions to make your debugging a little bit easier.

Read
Read
07
Inspect modules interactively
2 min read Screencast available Premium

Python's -i flag can be a handy tool for poking around within a module or script just after it's been run.

Read
Read
08
Python's assert statement
5 min read Screencast available Premium

Python's assert statement can be used in automated tests, and to validate certain conditions that might cause bugs if left unchecked.

Read
Read

Continue exploring

Profile picture of Trey

Learn something new about Python every week

My name is Trey Hunner. I publish new Python articles and screencasts every week through Python Morsels. If you want to learn something new about Python every week, join Python Morsels!

Join Python Morsels ✨