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 ')
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))