Debugging

Your code has a bug in it. What now?

8 articles · 51 min read
5 screencasts · 18 min watch
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
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
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
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
Inspecting objects
5 min read Screencast available

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

Read
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
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
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

Continue exploring

Profile picture of Trey

Learn something new about Python

My name is Trey Hunner. I publish new Python articles and screencasts through Python Morsels. If you want to keep learning new things about Python, join Python Morsels!

Join Python Morsels ✨