- Python Built-in Functions
- Python All Built-in Functions
- Python print() Function
- Python input() Function
- Python int() Function
- Python float() Function
- Python len() Function
- Python range() Function
- Python str() Function
- Python ord() Function
- Python chr() Function
- Python ascii() Function
- Python pow() Function
- Python type() Function
- Python List Functions
- Python list() Function
- Python insert() Function
- Python append() Function
- Python extend() Function
- Python pop() Function
- Python remove() Function
- Python reverse() Function
- Python sort() Function
- Python sorted() Function
- Python Dictionary Functions
- Python dict() Function
- Python update() Function
- Python get() Function
- Python keys() Function
- Python setdefault() Function
- Python fromkeys() Function
- Python items() Function
- Python popitem() Function
- Python Tuple Function
- Python tuple() Function
- Python Set Functions
- Python set() Function
- Python frozenset() Function
- Python String Functions
- Python split() Function
- Python join() Function
- Python format() Function
- Python replace() Function
- Python Iterator Functions
- Python iter() Function
- Python min() Function
- Python max() Function
- Python sum() Function
- Python count() Function
- Python index() Function
- Python copy() Function
- Python clear() Function
- Python next() Function
- Python filter() Function
- Python enumerate() Function
- Python zip() Function
- Python reversed() Function
- Python Number Functions
- Python abs() Function
- Python bin() Function
- Python oct() Function
- Python hex() Function
- Python round() Function
- Python divmod() Function
- Python complex() Function
- Python File Handling Functions
- Python open() Function
- Python read() Function
- Python readable() Function
- Python readline() Function
- Python readlines() Function
- Python write() Function
- Python writable() Function
- Python writelines() Function
- Python close() Function
- Python seek() Function
- Python tell() Function
- Python flush() Function
- Python fileno() Function
- Python truncate() Function
- Python Class Functions
- Python object() Function
- Python property() Function
- Python getattr() Function
- Python setattr() Function
- Python hasattr() Function
- Python delattr() Function
- Python classmethod() Function
- Python staticmethod() Function
- Python issubclass() Function
- Python super() Function
- Python Misc Functions
- Python all() Function
- Python any() Function
- Python isatty() Function
- Python bool() Function
- Python callable() Function
- Python globals() Function
- Python locals() Function
- Python dir() Function
- Python id() Function
- Python isinstance() Function
- Python map() Function
- Python repr() Function
- Python slice() Function
- Python vars() Function
- Python Advance Functions
- Python help() Function
- Python hash() Function
- Python breakpoint() Function
- Python bytes() Function
- Python bytearray() Function
- Python memoryview() Function
- Python compile() Function
- Python eval() Function
- Python exec() Function
- Python Tutorial
- Python Tutorial
- Python Examples
- Python Examples
Python breakpoint() Function
The breakpoint() function in Python drops into the debugger at the call site. That is, after calling the function breakpoint() into your Python program, the interpreter passes the control to the debugger. For example:
mylist = list() for i in range(10): a.append(i) if i == 5: breakpoint() print(mylist)
The snapshot given below shows the initial output produced by this Python program:
That is, when the value of i becomes equal to 5, then the condition of if evaluates to be True, therefore program flow goes inside the if block and the statement:
breakpoint()
gets executed. So the interpreter passed the control to the debugger. That means, no further execution of the code processed. Now using the debugger, we can execute and debug the code. For example, let me type print(mylist) to print the previously defined list, as shown in the snapshot given below:
That is, before the execution of breakpoint(), the element 0, 1, 2, 3, 4, 5 were appended in the list named
mylist. Therefore the print(mylist) prints the list. Now let's type help and press
ENTER
key to get all the command to work while using this Python debugger, like shown in the
snapshot given below:
Important - You can use the continue keyword to continue the execution of the code, to get/print the final output, and close the debug, as shown in the snapshot given below:
Python breakpoint() Function Syntax
The syntax of breakpoint() function is:
breakpoint(*args, **kws)
The breakpoint() function calls sys.breakpointhook(), passing the args, and kws straight through.
By Default - The sys.breakpointhook() calls pdb.set_trace() expecting no arguments.
Note: The function breakpoint() provides convenient way to use the same without explicitly importing the pdb, to enter the debugger. That is, use breakpoint() directly, without importing anything, to enter into the debugger.
Python breakpoint() Function Example
Here is an example of breakpoint() function in Python:
x = [1, 2, 4, 5] print(x) breakpoint() x = [10, 20, 30] print(x) x = ["codes", "cracker"] print(x)
The output produced by this Python program, demonstrating the breakpoint() function, is shown in the snapshot given below:
After the use of breakpoint(), the last two statements were not interpreted by the interpreter. Because after the use of breakpoint(), interpreter passed the control to the debugger. But don't worry, we can execute the code, in the debug mode too. For example, the next command is used to execute the next statement after the breakpoint() function. Before using the next command, let me use the print(x) to see what will be the output:
See, the list x still refers to the list with elements 1, 2, 4, 5, means that the statement:
x = [10, 20, 30]
is not executed. Therefore let me use the next command to execute the next statement and use the print(x) to print the list x with newly assigned list items, as shown in the snapshot given below:
You can use continue command to continue the execution of the code, after the breakpoint() to execute all the remaining codes and stops the execution of the program, like shown in the snapshot given below:
A lot of things you can do with your own debugging window created using your own code.
« Previous Function Next Function »