breakpoint()

breakpoint() to stop execution of program

We can stop execution of the script at a point and check the value ( or result ) of different process till that point. From this stop point we can again continue execution of the rest of the processes.

Let us see this example.
a=5
print(a)
breakpoint()
a="Welcome"
print(a)
After printing value of a as 5, our process will stop. It will prompt to enter value. We can enter c to further continue the program. We can quit from this point by entering q

This is the final output.
5
--Return--
> <ipython-input-11-bf9737819636>(3)<module>()->None
-> breakpoint()
(Pdb) c
Welcome

with condition

We can use if else and based on condition use the brakpoint()
x=13
if x >10:
    print(x)
    breakpoint() # stop execution 
else:
    print('Value is fine ')
Using inside class
class Animal():

     #class attributes
    species='carnivores'

     #instance attributes
    def __init__(self1,name1,age,weight):
        self1.name= name1
        breakpoint()
        self1.age=age
        self1.weight=weight
        self1.height=5  #instance attribute

 #instantiate the Animal  class
tiger=Animal("Ronald",5,15)  # tiger is an object of Animal class
breakpoint()
 # access the instance attributes
print("{} is {} years old animal".format( tiger.name, tiger.age))
All Built in Functions in Python chr() ord()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer