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?
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.
Need to troubleshoot an error in your Python code? Use Python's built-in breakpoint function to launch the Python debugger.
Python's help() function accepts more than functions, modules, and objects. The help() function can lookup help for symbols, keywords, and topics!
I rely on 4 functions for inspecting Python objects: type, help, dir, and vars.
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.
Python's -i flag can be a handy tool for poking around within a module or script just after it's been run.
Python's assert statement can be used in automated tests, and to validate certain conditions that might cause bugs if left unchecked.
Continue exploring
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!