Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Step 4: Repeat

00:00 In the previous lesson, you identified a possible error, and you made a change. Now you’re on step four of the debugging steps, where you will repeat steps one to three as needed until the code works as expected.

00:15 So head back over to IDLE and restart your script in the debugger. Don’t forget to save it first. Your debugger stops again just before executing the first line.

00:28 So press Go to go all the way to the first breakpoint. Again, you can see the local variables that have been defined inside of the scope of your function.

00:38 Now go ahead and press Step to see what happens to new_word. So I press Step once, and I can see that new_word is here.

00:47 We have the character 'h' that the loop is looking at. Now press Step again, and it’s looking much better now. The new_word variable now points to the string '_h_', which is what you expect.

01:02 So keep stepping through this and see what happens to your new_word variable. And this is looking great. It keeps adding each letter of the word, separated by an underscore, just as you wanted to. Let’s go to the end of the program,

01:20 and you can see that the expected output appears in your interactive window. That’s great. You had a success. Everything works as expected. So in this case, your first attempt at fixing the bug worked, so you don’t need to repeat steps one to three anymore. This won’t always be the case.

01:41 Sometimes you’ll have to repeat the process several times before you fix a bug.

01:47 So in the last four lessons, you went through all the four debugging steps: started by guessing which section may contain the bug, set the breakpoint and inspected the code by stepping through it with your debugger, then you identified the possible error and made a change, and in this case, the change actually fixed the bug, so you didn’t need to repeat steps one to three because your code already worked as expected. These debugging steps are really helpful to keep in mind.

02:13 Use them as your blueprint for approaching any bugs that you run into while coding up your own programs. But what should you do if you don’t have access to a debugger? In the next lesson, you’ll take a look at an alternative way of debugging that you can do also if you don’t have access to a debugger.

Become a Member to join the conversation.