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 your subtitle preferences 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 refer to our video player troubleshooting guide for assistance.

Breakpoints, Go, and Quit

00:00 In the previous lesson, you’ve used Step, Out, and Over to step through your code, more or less line by line. Often, however, you may know that the bug must be in a particular section of your code, but you probably don’t know exactly where.

00:16 And then, rather than clicking Step all day long, you can set a breakpoint that tells the debugger to continuously run all the code until it reaches the breakpoint. In this lesson, you’ll set a breakpoint and you’ll use the Go button to inspect certain parts of your script more specifically. And by the way, breakpoints just tell the debugger when to pause code execution so that you can take a look at the current state of the program. They don’t actually break anything.

00:45 To set a breakpoint, click on the line of code that you want to set it on and do a right-click, or Control-click on Mac, then select the option Set Breakpoint. IDLE highlights the line in yellow to indicate that your breakpoint has been set. To remove a breakpoint, do the same, but select Clear Breakpoint.

01:06 You’ll see that the highlighting disappears.

01:09 Now go ahead and set the breakpoint on line 3 of your short script. If your debugger is still running, then press the Quit button to stop the debugger.

01:21 This will not close the window, and the debug session will stay on. It will just quit the debugger for now. You know that it’s currently not running if the buttons are grayed out.

01:33 Now, go ahead and run your file again, pressing F5. The interactive window will tell you that this is a restart, and the debugger is still on. At the same time, you’ll also see that the buttons in the Debug Control window are interactive again. And just as before, you can see that in the Stack panel, the debugger tells you '__main__'.<module>(), line 1: for i in range(1, 4):.

02:00 So again, the debugger stopped just before executing line 1 of your script. Now, instead of stepping through your code using Step, you will use the Go button that, in combination with a breakpoint, will run the code until it hits a breakpoint.

02:18 So go ahead and press Go and then inspect the state of your Debug Control window. You can see the Stack now tells you that it stopped just before line 3, instead of line 3 as before, when you used the Step button. Also, inside of your Globals panel, you can see that both i and j are already defined.

02:40 If you press Go again, then Python will continue running the for loop until it hits the next breakpoint, which is just before the next print() function. As a result, you can see i is 1 and j is 2 printed to your interactive window, and you can also see that the variables i and j have both changed, and now point to the values 2 and 4 respectively.

03:06 If you press Go again, then Python runs the third iteration of your for loop and stops just before executing the final call to print().

03:15 You can see that i and j now point to the values 3 and 6.

03:21 Now, just as before, if you press Go once more, then your program is going to run to the end and finish. And just to try out the Quit button, instead of running this final iteration of the loop, you will press Quit and see what changes there.

03:39 You can see that the execution of the debugger stopped before running the third loop, and your Debug Control window is in the non-interactive state.

03:50 And that completes the walkthrough over the functions of your Debug Control window in IDLE. In this lesson, you’ve learned about breakpoints, the Go, and the Quit button.

04:02 You can set breakpoints by right-clicking, or Control-clicking on a Mac, and selecting Set Breakpoint, and then you can use the Go button to run all the code until the next breakpoint.

04:14 The combination of these two features allow you to pinpoint specific areas in your code where you want to investigate the current state of the variables.

04:23 This is a great help when debugging. Finally, if you want to stop your debugging session, you can press Quit.

04:31 In the next lesson, you’ll look at an actually buggy little script, and you will use your newly learned skills with the IDLE Debug Control window to find and fix the bug.

Become a Member to join the conversation.